SlideShare a Scribd company logo
1 of 15
Download to read offline
Selecting Design PatternsSelecting Design Patterns
João Miguel PereiraJoão Miguel Pereira
http://jpereira.eu
May 2012
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons Attribution‐NonCommercial‐ShareAlike 3.0 
Unported License.
Selecting Design PatternsSelecting Design Patterns
• Pattern IntentPattern Intent
• Pattern Purpose & Scope
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
2
Selecting Design PatternsSelecting Design Patterns
• Pattern IntentPattern Intent
• Pattern Purpose & Scope
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
3
Pattern IntentPattern Intent
Intent Pattern
Convert the interface of a class into AdapterConvert the interface of a class into 
another interface clients expect. Adapter 
lets classes work together that couldn't 
otherwise because of incompatible 
Adapter
interfaces
Decouple an abstraction from its 
implementation so that the two can vary 
i d d tl
Bridge
independently 
Separate the construction of a complex 
object from its representation so that the 
same construction process can create
Builder
same construction process can create 
different representations. 
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
4
Pattern IntentPattern Intent
Intent Pattern
Avoid coupling the sender of a request to Chain of ResponsibilityAvoid coupling the sender of a request to 
its receiver by giving more than one 
object a chance to handle the request. 
Chain the receiving objects and pass the 
Chain of Responsibility
request along the chain until an object 
handles it. 
Encapsulate a request as an object, 
th b l tti t i li t
Command
thereby letting you parameterize clients 
with different requests, queue or log 
requests, and support undoable 
operations. 
Compose objects into tree structures to 
represent part‐whole hierarchies. 
Composite lets clients treat individual 
Composite
objects and compositions of objects 
uniformly. 
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
5
Pattern IntentPattern Intent
Intent Pattern
Attach additional responsibilities to an DecoratorAttach additional responsibilities to an 
object dynamically. Decorators provide a 
flexible alternative to subclassing for 
extending functionality. 
Decorator
Provide a unified interface to a set of 
interfaces in a subsystem. Facade defines 
a higher‐level interface that makes the 
b t i t
Façade
subsystem easier to use. 
Define an interface for creating an object, 
but let subclasses decide which class to 
instantiate Factory Method lets a class
Factory Method
instantiate. Factory Method lets a class 
defer instantiation to subclasses. 
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
6
Pattern IntentPattern Intent
Intent Pattern
Use sharing to support large numbers of FlyweightUse sharing to support large numbers of 
fine‐grained objects efficiently. 
Flyweight
Given a language, define a representation 
for its grammar along with an interpreter 
Interpreter
g g p
that uses the representation to interpret 
sentences in the language. 
Provide a way to access the elements of  Iterator
an aggregate object sequentially without 
exposing its underlying representation. 
Define an object that encapsulates how a 
f bj i M di
Mediator
set of objects interact. Mediator 
promotes loose coupling by keeping 
objects from referring to each other 
explicitly, and it lets you vary their p y, y y
interaction independently. 
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
7
Pattern IntentPattern Intent
Intent Pattern
Without violating encapsulation capture MementoWithout violating encapsulation, capture 
and externalize an object's internal state 
so that the object can be restored to this 
state later. 
Memento
Define a one‐to‐many dependency 
between objects so that when one object 
changes state, all its dependents are 
tifi d d d t d t ti ll
Observer
notified and updated automatically. 
Specify the kinds of objects to create 
using a prototypical instance, and create 
new objects by copying this prototype
Prototype
new objects by copying this prototype. 
Provide a surrogate or placeholder for 
another object to control access to it. 
Proxy
Ensure a class only has one instance and SingletonEnsure a class only has one instance, and 
provide a global point of access to it. 
Singleton
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
8
Pattern IntentPattern Intent
Intent Pattern
Allow an object to alter its behavior when StateAllow an object to alter its behavior when 
its internal state changes. The object will 
appear to change its class. 
State
Define a family of algorithms, encapsulate  Strategyy g , p
each one, and make them 
interchangeable. Strategy lets the 
algorithm vary independently from clients 
th t it
gy
that use it. 
Define the skeleton of an algorithm in an 
operation, deferring some steps to 
subclasses Template Method lets
Template Method
subclasses. Template Method lets 
subclasses redefine certain steps of an 
algorithm without changing the 
algorithm's structure. 
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
9
Pattern IntentPattern Intent
Intent Pattern
Represent an operation to be performed VisitorRepresent an operation to be performed 
on the elements of an object structure. 
Visitor lets you define a new operation 
without changing the classes of the 
Visitor
elements on which it operates. 
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
10
Selecting Design PatternsSelecting Design Patterns
• Pattern IntentPattern Intent
• Pattern Purpose & Scope
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
11
Pattern PurposePattern Purpose
Purpose Classification
The process of object 
creation 
Creational
The composition of classes 
or objects 
Structural
The way in which classes 
or objects interact and 
distribute responsibility
Behavioral 
distribute responsibility 
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
12
Pattern ScopePattern Scope
Scope What does it means
Class Affect relationships between classes and 
their subclasses, generally through 
inheritance. Cannot be changed in 
runtime since the hierarchy is static‐fixedruntime, since the hierarchy is static‐fixed 
at compile time.
Object Affect relationship between objects, 
which can be changed at run‐time and are g
more dynamic.
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
13
Classification by Purpose and ScopeClassification by Purpose and Scope
Purpose
Creational Structural Behavioral
Class •Factory Method •Adapter •Interpreter
•Template Method
Object •Abstract Factory 
•Builder
•Prototype 
•Bridge
•Composite
•Chain of Responsibility
•Command
•Iterator
SS
•Singleton  •Decorator
•Facade
•Flyweight
•Proxy 
•Mediator
•Memento
•Observer 
•State
c
o
p
e
c
o
p
e
•Strategy
•Visitor 
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
14
Design Patterns
The Book
http://amzn.to/book_DPEROOS 
Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons 
Attribution‐NonCommercial‐ShareAlike 3.0 Unported License.
15

More Related Content

What's hot

Modelling the User Interface
Modelling the User InterfaceModelling the User Interface
Modelling the User InterfacePedro J. Molina
 
Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...Marco Brambilla
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaEdureka!
 
MoDisco EclipseCon2010
MoDisco EclipseCon2010MoDisco EclipseCon2010
MoDisco EclipseCon2010fmadiot
 
Creational Patterns
Creational PatternsCreational Patterns
Creational PatternsAsma CHERIF
 
Design patterns through refactoring
Design patterns through refactoringDesign patterns through refactoring
Design patterns through refactoringGanesh Samarthyam
 
Model-Driven Software Engineering in Practice - Chapter 1 - Introduction
Model-Driven Software Engineering in Practice - Chapter 1 - IntroductionModel-Driven Software Engineering in Practice - Chapter 1 - Introduction
Model-Driven Software Engineering in Practice - Chapter 1 - IntroductionMarco Brambilla
 
Generating an Android App with Acceleo (Eclipse Summit Europe 2010)
Generating an Android App with Acceleo (Eclipse Summit Europe 2010)Generating an Android App with Acceleo (Eclipse Summit Europe 2010)
Generating an Android App with Acceleo (Eclipse Summit Europe 2010)mikaelbarbero
 
SOLID Principles and Design Patterns
SOLID Principles and Design PatternsSOLID Principles and Design Patterns
SOLID Principles and Design PatternsGanesh Samarthyam
 
Java design patterns
Java design patternsJava design patterns
Java design patternsShawn Brito
 
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...Jordi Cabot
 
Introduction to Domain Driven Design
Introduction to Domain Driven DesignIntroduction to Domain Driven Design
Introduction to Domain Driven DesignChristos Tsakostas
 
Opps approch of software development
Opps approch of software developmentOpps approch of software development
Opps approch of software developmentRaja Babu
 

What's hot (14)

Modelling the User Interface
Modelling the User InterfaceModelling the User Interface
Modelling the User Interface
 
Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | Edureka
 
MoDisco EclipseCon2010
MoDisco EclipseCon2010MoDisco EclipseCon2010
MoDisco EclipseCon2010
 
Creational Patterns
Creational PatternsCreational Patterns
Creational Patterns
 
01 mde principles
01 mde principles01 mde principles
01 mde principles
 
Design patterns through refactoring
Design patterns through refactoringDesign patterns through refactoring
Design patterns through refactoring
 
Model-Driven Software Engineering in Practice - Chapter 1 - Introduction
Model-Driven Software Engineering in Practice - Chapter 1 - IntroductionModel-Driven Software Engineering in Practice - Chapter 1 - Introduction
Model-Driven Software Engineering in Practice - Chapter 1 - Introduction
 
Generating an Android App with Acceleo (Eclipse Summit Europe 2010)
Generating an Android App with Acceleo (Eclipse Summit Europe 2010)Generating an Android App with Acceleo (Eclipse Summit Europe 2010)
Generating an Android App with Acceleo (Eclipse Summit Europe 2010)
 
SOLID Principles and Design Patterns
SOLID Principles and Design PatternsSOLID Principles and Design Patterns
SOLID Principles and Design Patterns
 
Java design patterns
Java design patternsJava design patterns
Java design patterns
 
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
 
Introduction to Domain Driven Design
Introduction to Domain Driven DesignIntroduction to Domain Driven Design
Introduction to Domain Driven Design
 
Opps approch of software development
Opps approch of software developmentOpps approch of software development
Opps approch of software development
 

Similar to Software Design Patterns - Selecting the right design pattern

Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptxSachin Patidar
 
ABSTRACT FACTORY AND SINGLETON DESIGN PATTERNS TO CREATE DECORATOR PATTERN OB...
ABSTRACT FACTORY AND SINGLETON DESIGN PATTERNS TO CREATE DECORATOR PATTERN OB...ABSTRACT FACTORY AND SINGLETON DESIGN PATTERNS TO CREATE DECORATOR PATTERN OB...
ABSTRACT FACTORY AND SINGLETON DESIGN PATTERNS TO CREATE DECORATOR PATTERN OB...ijait
 
Can't Handle My Scale v2
Can't Handle My Scale v2Can't Handle My Scale v2
Can't Handle My Scale v2Michele Titolo
 
The Conceptual Model
The Conceptual ModelThe Conceptual Model
The Conceptual ModelTim Sheiner
 
What is IETM and What is Not IETM.pdf cnp
What is IETM and What is Not IETM.pdf cnpWhat is IETM and What is Not IETM.pdf cnp
What is IETM and What is Not IETM.pdf cnps1000dcodeandpixels
 
Tech Agility at TD Ameritrade
Tech Agility at TD AmeritradeTech Agility at TD Ameritrade
Tech Agility at TD AmeritradeVMware Tanzu
 
Ni week no designer, no problem
Ni week no designer, no problem Ni week no designer, no problem
Ni week no designer, no problem Jenica Welch
 
[PPT] _ Unit 3 _ Experiment.pptx
[PPT] _ Unit 3 _ Experiment.pptx[PPT] _ Unit 3 _ Experiment.pptx
[PPT] _ Unit 3 _ Experiment.pptxSelvaraj Seerangan
 
Design pattern application
Design pattern applicationDesign pattern application
Design pattern applicationgayatri thakur
 
Discrete Event Simulation, CASE tool built using C#
Discrete Event Simulation, CASE tool built using C#Discrete Event Simulation, CASE tool built using C#
Discrete Event Simulation, CASE tool built using C#Ron Perlmuter
 
SampleBoard - Mood Board Creator for Education
SampleBoard - Mood Board Creator for EducationSampleBoard - Mood Board Creator for Education
SampleBoard - Mood Board Creator for EducationSampleBoard
 
Lightweight Model-Driven Engineering
Lightweight Model-Driven EngineeringLightweight Model-Driven Engineering
Lightweight Model-Driven EngineeringJordi Cabot
 
Presentation Builder Pattern OOAD
Presentation Builder Pattern OOADPresentation Builder Pattern OOAD
Presentation Builder Pattern OOADPeng Sony
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia ContiniWEBdeBS
 
BTEC Creative Digital Media Production Unit 2 introduction
BTEC Creative Digital Media Production Unit 2 introductionBTEC Creative Digital Media Production Unit 2 introduction
BTEC Creative Digital Media Production Unit 2 introductionJMAcreativemedia
 

Similar to Software Design Patterns - Selecting the right design pattern (20)

Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Design pattern
Design patternDesign pattern
Design pattern
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptx
 
ABSTRACT FACTORY AND SINGLETON DESIGN PATTERNS TO CREATE DECORATOR PATTERN OB...
ABSTRACT FACTORY AND SINGLETON DESIGN PATTERNS TO CREATE DECORATOR PATTERN OB...ABSTRACT FACTORY AND SINGLETON DESIGN PATTERNS TO CREATE DECORATOR PATTERN OB...
ABSTRACT FACTORY AND SINGLETON DESIGN PATTERNS TO CREATE DECORATOR PATTERN OB...
 
Can't Handle My Scale v2
Can't Handle My Scale v2Can't Handle My Scale v2
Can't Handle My Scale v2
 
Design pattern
Design patternDesign pattern
Design pattern
 
The Conceptual Model
The Conceptual ModelThe Conceptual Model
The Conceptual Model
 
What is IETM and What is Not IETM.pdf cnp
What is IETM and What is Not IETM.pdf cnpWhat is IETM and What is Not IETM.pdf cnp
What is IETM and What is Not IETM.pdf cnp
 
Tech Agility at TD Ameritrade
Tech Agility at TD AmeritradeTech Agility at TD Ameritrade
Tech Agility at TD Ameritrade
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ni week no designer, no problem
Ni week no designer, no problem Ni week no designer, no problem
Ni week no designer, no problem
 
[PPT] _ Unit 3 _ Experiment.pptx
[PPT] _ Unit 3 _ Experiment.pptx[PPT] _ Unit 3 _ Experiment.pptx
[PPT] _ Unit 3 _ Experiment.pptx
 
Design pattern application
Design pattern applicationDesign pattern application
Design pattern application
 
Discrete Event Simulation, CASE tool built using C#
Discrete Event Simulation, CASE tool built using C#Discrete Event Simulation, CASE tool built using C#
Discrete Event Simulation, CASE tool built using C#
 
SampleBoard - Mood Board Creator for Education
SampleBoard - Mood Board Creator for EducationSampleBoard - Mood Board Creator for Education
SampleBoard - Mood Board Creator for Education
 
Lightweight Model-Driven Engineering
Lightweight Model-Driven EngineeringLightweight Model-Driven Engineering
Lightweight Model-Driven Engineering
 
Presentation Builder Pattern OOAD
Presentation Builder Pattern OOADPresentation Builder Pattern OOAD
Presentation Builder Pattern OOAD
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
 
BTEC Creative Digital Media Production Unit 2 introduction
BTEC Creative Digital Media Production Unit 2 introductionBTEC Creative Digital Media Production Unit 2 introduction
BTEC Creative Digital Media Production Unit 2 introduction
 

Recently uploaded

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Software Design Patterns - Selecting the right design pattern

  • 1. Selecting Design PatternsSelecting Design Patterns João Miguel PereiraJoão Miguel Pereira http://jpereira.eu May 2012 Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons Attribution‐NonCommercial‐ShareAlike 3.0  Unported License.
  • 2. Selecting Design PatternsSelecting Design Patterns • Pattern IntentPattern Intent • Pattern Purpose & Scope Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 2
  • 3. Selecting Design PatternsSelecting Design Patterns • Pattern IntentPattern Intent • Pattern Purpose & Scope Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 3
  • 4. Pattern IntentPattern Intent Intent Pattern Convert the interface of a class into AdapterConvert the interface of a class into  another interface clients expect. Adapter  lets classes work together that couldn't  otherwise because of incompatible  Adapter interfaces Decouple an abstraction from its  implementation so that the two can vary  i d d tl Bridge independently  Separate the construction of a complex  object from its representation so that the  same construction process can create Builder same construction process can create  different representations.  Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 4
  • 5. Pattern IntentPattern Intent Intent Pattern Avoid coupling the sender of a request to Chain of ResponsibilityAvoid coupling the sender of a request to  its receiver by giving more than one  object a chance to handle the request.  Chain the receiving objects and pass the  Chain of Responsibility request along the chain until an object  handles it.  Encapsulate a request as an object,  th b l tti t i li t Command thereby letting you parameterize clients  with different requests, queue or log  requests, and support undoable  operations.  Compose objects into tree structures to  represent part‐whole hierarchies.  Composite lets clients treat individual  Composite objects and compositions of objects  uniformly.  Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 5
  • 6. Pattern IntentPattern Intent Intent Pattern Attach additional responsibilities to an DecoratorAttach additional responsibilities to an  object dynamically. Decorators provide a  flexible alternative to subclassing for  extending functionality.  Decorator Provide a unified interface to a set of  interfaces in a subsystem. Facade defines  a higher‐level interface that makes the  b t i t Façade subsystem easier to use.  Define an interface for creating an object,  but let subclasses decide which class to  instantiate Factory Method lets a class Factory Method instantiate. Factory Method lets a class  defer instantiation to subclasses.  Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 6
  • 7. Pattern IntentPattern Intent Intent Pattern Use sharing to support large numbers of FlyweightUse sharing to support large numbers of  fine‐grained objects efficiently.  Flyweight Given a language, define a representation  for its grammar along with an interpreter  Interpreter g g p that uses the representation to interpret  sentences in the language.  Provide a way to access the elements of  Iterator an aggregate object sequentially without  exposing its underlying representation.  Define an object that encapsulates how a  f bj i M di Mediator set of objects interact. Mediator  promotes loose coupling by keeping  objects from referring to each other  explicitly, and it lets you vary their p y, y y interaction independently.  Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 7
  • 8. Pattern IntentPattern Intent Intent Pattern Without violating encapsulation capture MementoWithout violating encapsulation, capture  and externalize an object's internal state  so that the object can be restored to this  state later.  Memento Define a one‐to‐many dependency  between objects so that when one object  changes state, all its dependents are  tifi d d d t d t ti ll Observer notified and updated automatically.  Specify the kinds of objects to create  using a prototypical instance, and create  new objects by copying this prototype Prototype new objects by copying this prototype.  Provide a surrogate or placeholder for  another object to control access to it.  Proxy Ensure a class only has one instance and SingletonEnsure a class only has one instance, and  provide a global point of access to it.  Singleton Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 8
  • 9. Pattern IntentPattern Intent Intent Pattern Allow an object to alter its behavior when StateAllow an object to alter its behavior when  its internal state changes. The object will  appear to change its class.  State Define a family of algorithms, encapsulate  Strategyy g , p each one, and make them  interchangeable. Strategy lets the  algorithm vary independently from clients  th t it gy that use it.  Define the skeleton of an algorithm in an  operation, deferring some steps to  subclasses Template Method lets Template Method subclasses. Template Method lets  subclasses redefine certain steps of an  algorithm without changing the  algorithm's structure.  Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 9
  • 10. Pattern IntentPattern Intent Intent Pattern Represent an operation to be performed VisitorRepresent an operation to be performed  on the elements of an object structure.  Visitor lets you define a new operation  without changing the classes of the  Visitor elements on which it operates.  Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 10
  • 11. Selecting Design PatternsSelecting Design Patterns • Pattern IntentPattern Intent • Pattern Purpose & Scope Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 11
  • 12. Pattern PurposePattern Purpose Purpose Classification The process of object  creation  Creational The composition of classes  or objects  Structural The way in which classes  or objects interact and  distribute responsibility Behavioral  distribute responsibility  Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 12
  • 13. Pattern ScopePattern Scope Scope What does it means Class Affect relationships between classes and  their subclasses, generally through  inheritance. Cannot be changed in  runtime since the hierarchy is static‐fixedruntime, since the hierarchy is static‐fixed  at compile time. Object Affect relationship between objects,  which can be changed at run‐time and are g more dynamic. Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 13
  • 14. Classification by Purpose and ScopeClassification by Purpose and Scope Purpose Creational Structural Behavioral Class •Factory Method •Adapter •Interpreter •Template Method Object •Abstract Factory  •Builder •Prototype  •Bridge •Composite •Chain of Responsibility •Command •Iterator SS •Singleton  •Decorator •Facade •Flyweight •Proxy  •Mediator •Memento •Observer  •State c o p e c o p e •Strategy •Visitor  Selecting Design Patterns by João Miguel Pereira is licensed under a Creative Commons  Attribution‐NonCommercial‐ShareAlike 3.0 Unported License. 14