SlideShare a Scribd company logo
Design Patterns and their applications
Presenter: Bui Tien Hiep
1. What is Design Pattern.
2. Why Design Pattern.
3. How to use Design Pattern.
4. The principle of Design Pattern
5. UML relationship
6. Gang of Four Design Pattern
7. Example apply Design Pattern in EC
Contents
"Each pattern describes a problem which occurs over and over again in our environment, and then
describes the core of the solution to that problem, in such a way that you can use this solution a
million times over, without ever doing it the same way twice“ – Pro.Christopher Alexander,
University of California, Berkeley
What is Design Pattern?
Pattern = Name + Problem + Solution + Consequences
What is Design Pattern?
In general, a pattern has four essential elements:
1. The pattern name is a handle we can use to describe a design problem, its
solutions, and consequences in a word or two.
2. The problem describes when to apply the pattern. It explains the problem
and its context.
3. The solution describes the elements that make up the design, their
relationships, responsibilities, and collaborations.
4. The consequences are the results and trade-offs of applying the pattern.
What is Design Parttern?(2)
• Good designers do not solve every problem from first principles. They
reuse solutions.
• Practitioners do not do a good job of recording experience in software
design for others to use. Patterns help solve this problem.
Why Design Pattern?
Once you've picked a design pattern, how do you use it? Here's a step-by-step
approach to applying a design pattern effectively:
1. Read the pattern once through for an overview. Pay particular attention
to the Applicability and Consequences sections to ensure the pattern is
right for your problem.
How to Use a Design Pattern?(1)
2. Go back and study the Structure,
Participants, and Collaborations sections.
Make sure you understand the classes and
objects in the pattern and how they relate to one
another.
3. Look at the Sample Code section to see a concrete example of the pattern
in code. Studying the code helps you learn how to implement the pattern.
4. Choose names for pattern participants that are meaningful in the
application context. The names for participants in design patterns are usually
too abstract to appear directly in an application. Nevertheless, it's useful
to incorporate the participant name into the name that appears in the
application. That helps make the pattern more explicit in the
implementation.
How to Use a Design Pattern?(2)
5. Define the classes. Declare their interfaces, establish their inheritance
relationships, and define the instance variables that represent data and
object references. Identify existing classes in your application that the
pattern will affect, and modify them accordingly.
6. Define application-specific names for operations in the pattern. Here again, the
names generally depend on the application. Use the responsibilities
and collaborations associated with each operation as a guide. Also, be
consistent in your naming conventions. For example, you might use the
"Create-" prefix consistently to denote a factory method.
7. Implement the operations to carry out the responsibilities and
collaborations in the pattern. The Implementation section offers hints to
guide you in the implementation
How to Use a Design Pattern?(2)
The principle of Design Pattern
The principle of one pattern can be summarized in five main points:
1. “Separate out the things that change from those that stay the same.”
2. “Program to an interface, not an implementation”
3. “Prefer composition over inheritance”
4. “Delegate, delegate, delegate.”
5. “You ain’t gonna need it”
UML Relationships
Gang of Four Design Patterns
Intent:
• A creational pattern dealing with creating
objects without knowing their concrete
class
• It defines an interface for creating an
object, but let the subclasses decide which
class to instantiate
• Useful when concrete class of object
should be decided at runtime according to
parameters
Problem:
• A framework needs to standardize the
architectural model for a range of
applications, but allow for individual
applications to define their own domain
objects and provide for their instantiation.
Creational: Factory
Intent:
• Separate the construction of a complex
object from its representation so that the
same construction process can create
different representations.
• Parse a complex representation, create one
of several targets
Problem:
• An application needs to create the elements
of a complex aggregate. The specification
for the aggregate exists on secondary
storage and one of many representations
needs to be built in primary storage.
Creational: Builder
Creational: Prototype
Intent:
• Specify the kinds of objects to create using
a prototypical instance, and create new
objects by copying this prototype.
• Co-opt one instance of a class for use as a
breeder of all future instances.
Problem:
• Application "hard wires" the class of object
to create in each "new" expression.
Creational: Singleton
Intent:
• Ensure a class has only one instance, and
provide a global point of access to it.
• Encapsulated "just-in-time initialization" or
"initialization on first use".
Problem:
• Application needs one, and only one,
instance of an object. Additionally, lazy
initialization and global access are
necessary.
Structural: Adapter
Intent:
• Convert the interface of a class into another
interface clients expect. Adapter lets classes
work together that couldn't otherwise
because of incompatible interfaces.
• Wrap an existing class with a new interface.
• Impedance match an old component to a
new system
Problem:
• An "off the shelf" component offers
compelling functionality that you would like
to reuse, but its "view of the world" is not
compatible with the philosophy and
architecture of the system currently being
developed.
Structural: Brigde
Intent:
• Decouple an abstraction from its
implementation so that the two can vary
independently.
• Publish interface in an inheritance hierarchy,
and bury implementation in its own
inheritance hierarchy.
• Beyond encapsulation, to insulation
Problem:
• "Hardening of the software arteries" has
occurred by using subclassing of an abstract
base class to provide alternative
implementations. This locks in compile-time
binding between interface and
implementation. The abstraction and
implementation cannot be independently
extended or composed.
Structural: Composite
Intent:
• Compose objects into tree structures to
represent whole-part hierarchies. Composite
lets clients treat individual objects and
compositions of objects uniformly.
• Recursive composition
• "Directories contain entries, each of which
could be a directory."
• 1-to-many "has a" up the "is a" hierarchy
Problem:
• Application needs to manipulate a
hierarchical collection of "primitive" and
"composite" objects. Processing of a
primitive object is handled one way, and
processing of a composite object is handled
differently. Having to query the "type" of
each object before attempting to process it
is not desirable.
Structural: Decorator
Intent:
• Attach additional responsibilities to an object
dynamically. Decorators provide a flexible
alternative to subclassing for extending
functionality.
• Client-specified embellishment of a core
object by recursively wrapping it.
• Wrapping a gift, putting it in a box, and
wrapping the box.
Problem:
• You want to add behavior or state to
individual objects at run-time. Inheritance is
not feasible because it is static and applies
to an entire class.
Structural: Proxy
Intent:
• Provide a surrogate or placeholder for
another object to control access to it.
• Use an extra level of indirection to support
distributed, controlled, or intelligent access.
• Add a wrapper and delegation to protect the
real component from undue complexity.
Problem:
• You need to support resource-hungry
objects, and you do not want to instantiate
such objects unless and until they are
actually requested by the client
Behavioral: Chain of Responsibility
Intent:
• Avoid 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
request along the chain until an object handles it
• Launch-and-leave requests with a single processing
pipeline that contains many possible handlers.
• An object-oriented linked list with recursive traversal.
Problem:
• There is a potentially variable number of "handler" or
"processing element" or "node" objects, and a stream
of requests that must be handled. Need to efficiently
process the requests without hard-wiring handler
relationships and precedence, or request-to-handler
mappings.
Behavioral: Command
Intent:
• Encapsulate a request as an object, thereby
letting you parameterize clients with different
requests, queue or log requests, and support
undoable operations.
• Promote "invocation of a method on an
object" to full object status
• An object-oriented callback.
Problem:
• Need to issue requests to objects without
knowing anything about the operation being
requested or the receiver of the request.
Behavioral: Observer
Intent:
• Define a one-to-many dependency between
objects so that when one object changes state, all
its dependents are notified and updated
automatically.
• Encapsulate the core (or common or engine)
components in a Subject abstraction, and the
variable (or optional or user interface)
components in an Observer hierarchy.
• The "View" part of Model-View-Controller.
Problem:
• A large monolithic design does not scale well as
new graphing or monitoring requirements are
levied.
Behavioral: Template
Intent:
• Define the skeleton of an algorithm in an
operation, deferring some steps to client
subclasses. Template Method lets subclasses
redefine certain steps of an algorithm without
changing the algorithm's structure.
• Base class declares algorithm 'placeholders', and
derived classes implement the placeholders.
Problem:
• Two different components have significant
similarities, but demonstrate no reuse of common
interface or implementation. If a change common
to both components becomes necessary,
duplicate effort must be expended
Specification Design Pattern
Intent:
• Validation determines if a particular object
satisfies a certain criteria.
• Selection identifies those elements of a collection
that satisfy the given criteria
Problem:
• Need to clean way to encapsulate business logic
Example apply Design Pattern in EC
Problem:
Input: The expense list of a report and the policy list of company
Output: Policy violation messages.
Solution
Design Pattern Description
Specification Chaining the business rules
together using boolean logic.
Builder Create policy validation objects
Example apply Design Pattern in EC(2)
Example apply Design Pattern in EC(3)
Reference
1. http://sourcemaking.com/design_patterns
2. Design Patterns: Elements of Reusable Object-Oriented Software
3. http://www.cs.colorado.edu/~kena/classes/5448/s11/lectures/
4. http://en.wikipedia.org/wiki/Specification_pattern
Conclusion
QA?

More Related Content

What's hot (20)

PPTX
Basic Structural Modeling
AMITJain879
 
PPTX
Java socket programming
Mohammed Abdalla Youssif
 
PPTX
Relationship Among Token, Lexeme & Pattern
Bharat Rathore
 
PDF
Test Driven Development
Kumaresh Chandra Baruri
 
PPTX
Class and object_diagram
Sadhana28
 
PDF
Architecture of a search engine
Sylvain Utard
 
PPTX
Software Design and Modularity
Danyal Ahmad
 
PPS
Java rmi
kamal kotecha
 
PPTX
Software requirements specification
lavanya marichamy
 
PPTX
C# Framework class library
Prem Kumar Badri
 
PPTX
Introducing Technologies for Handling Big Data by Jaseela
Student
 
PPT
Collection Framework in java
CPD INDIA
 
PPTX
Servlets
Rajkiran Mummadi
 
PPTX
Exception Handling in C#
Abid Kohistani
 
PPTX
Loc and function point
Mitali Chugh
 
PPTX
jstl ( jsp standard tag library )
Adarsh Patel
 
PPTX
Software Myths
Rajat Bajaj
 
PPTX
Refactoring and code smells
Paul Nguyen
 
PPTX
Hash Function
ssuserdfb2da
 
PPTX
Java - Collections framework
Riccardo Cardin
 
Basic Structural Modeling
AMITJain879
 
Java socket programming
Mohammed Abdalla Youssif
 
Relationship Among Token, Lexeme & Pattern
Bharat Rathore
 
Test Driven Development
Kumaresh Chandra Baruri
 
Class and object_diagram
Sadhana28
 
Architecture of a search engine
Sylvain Utard
 
Software Design and Modularity
Danyal Ahmad
 
Java rmi
kamal kotecha
 
Software requirements specification
lavanya marichamy
 
C# Framework class library
Prem Kumar Badri
 
Introducing Technologies for Handling Big Data by Jaseela
Student
 
Collection Framework in java
CPD INDIA
 
Exception Handling in C#
Abid Kohistani
 
Loc and function point
Mitali Chugh
 
jstl ( jsp standard tag library )
Adarsh Patel
 
Software Myths
Rajat Bajaj
 
Refactoring and code smells
Paul Nguyen
 
Hash Function
ssuserdfb2da
 
Java - Collections framework
Riccardo Cardin
 

Viewers also liked (18)

PPTX
Readers brain
Yellowlees Douglas, Ph.D.
 
DOC
personal leadership plan
Daniel Sandoval
 
PPTX
Public Health Impact of Climate Change
Brianna O' Malley
 
PDF
brochure informativa ENG
Andrea Ferri
 
PPT
薛雅仲_4 b pe1001130
Piko Peng
 
PDF
2011 02-18 09-38-24-apostila_de_chakras
Infinito Quantico
 
PDF
June Coverstar
Daniel J. Zachmann
 
PPTX
Sieci neuronowe
grzesiekAAAAA
 
PDF
2013 Summer/Fall Saratogan
City of Saratoga
 
PPSX
презентация для переводчиков
Max Malkovych
 
PPTX
Digital Strategy - Business & Brand
Marcin Ladowski
 
PPT
新聞概述
Piko Peng
 
PPTX
Top 8 it service coordinator resume samples
owenrodriguez458
 
PDF
COMPANY_PRESENTATION20150424
GE LONG
 
PPTX
Najnowsze osiągnięcia robotyki
grzesiekAAAAA
 
PPTX
It services
maheshjara
 
PDF
2016 Winter Saratogan
City of Saratoga
 
PPTX
Top 8 adoption coordinator resume samples
owenrodriguez458
 
personal leadership plan
Daniel Sandoval
 
Public Health Impact of Climate Change
Brianna O' Malley
 
brochure informativa ENG
Andrea Ferri
 
薛雅仲_4 b pe1001130
Piko Peng
 
2011 02-18 09-38-24-apostila_de_chakras
Infinito Quantico
 
June Coverstar
Daniel J. Zachmann
 
Sieci neuronowe
grzesiekAAAAA
 
2013 Summer/Fall Saratogan
City of Saratoga
 
презентация для переводчиков
Max Malkovych
 
Digital Strategy - Business & Brand
Marcin Ladowski
 
新聞概述
Piko Peng
 
Top 8 it service coordinator resume samples
owenrodriguez458
 
COMPANY_PRESENTATION20150424
GE LONG
 
Najnowsze osiągnięcia robotyki
grzesiekAAAAA
 
It services
maheshjara
 
2016 Winter Saratogan
City of Saratoga
 
Top 8 adoption coordinator resume samples
owenrodriguez458
 
Ad

Similar to Design pattern and their application (20)

PPT
Chapter 4_Introduction to Patterns.ppt
RushikeshChikane1
 
PPT
Chapter 4_Introduction to Patterns.ppt
RushikeshChikane2
 
PDF
software engineering Design Patterns.pdf
mulugetaberihun3
 
ODP
Design Patterns Part1
Tom Chen
 
PPTX
Design patterns
Akhilesh Gupta
 
PPTX
Go f designpatterns 130116024923-phpapp02
Jagath Bandara Senanayaka
 
PPTX
Software Patterns
bonej010
 
PPT
Design Patterns
Rafael Coutinho
 
PPTX
note2_DesignPatterns (1).pptx
ReemaAsker1
 
PPT
Software Design Patterns
Satheesh Sukumaran
 
PPT
Software Design Patterns
Satheesh Sukumaran
 
PPTX
Architecture and design
himanshu_airon
 
PPT
Design patterns-sav
Nukala Gopala Krishna Murthy
 
PDF
Design Pattern in Software Engineering
Bilal Hassan
 
PPTX
Sda 9
AmberMughal5
 
PPTX
UNIT IV DESIGN PATTERNS.pptx
anguraju1
 
PPTX
Let us understand design pattern
Mindfire Solutions
 
PPTX
ap assignmnet presentation.pptx
AwanAdhikari
 
PPTX
Gof design patterns
Srikanth R Vaka
 
PDF
Design Patterns Java programming language.pdf
totallyrealmail420
 
Chapter 4_Introduction to Patterns.ppt
RushikeshChikane1
 
Chapter 4_Introduction to Patterns.ppt
RushikeshChikane2
 
software engineering Design Patterns.pdf
mulugetaberihun3
 
Design Patterns Part1
Tom Chen
 
Design patterns
Akhilesh Gupta
 
Go f designpatterns 130116024923-phpapp02
Jagath Bandara Senanayaka
 
Software Patterns
bonej010
 
Design Patterns
Rafael Coutinho
 
note2_DesignPatterns (1).pptx
ReemaAsker1
 
Software Design Patterns
Satheesh Sukumaran
 
Software Design Patterns
Satheesh Sukumaran
 
Architecture and design
himanshu_airon
 
Design patterns-sav
Nukala Gopala Krishna Murthy
 
Design Pattern in Software Engineering
Bilal Hassan
 
UNIT IV DESIGN PATTERNS.pptx
anguraju1
 
Let us understand design pattern
Mindfire Solutions
 
ap assignmnet presentation.pptx
AwanAdhikari
 
Gof design patterns
Srikanth R Vaka
 
Design Patterns Java programming language.pdf
totallyrealmail420
 
Ad

Recently uploaded (20)

PDF
How Attendance Management Software is Revolutionizing Education.pdf
Pikmykid
 
PDF
Softaken CSV to vCard Converter accurately converts CSV files to vCard
markwillsonmw004
 
PPTX
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
 
PPTX
Get Started with Maestro: Agent, Robot, and Human in Action – Session 5 of 5
klpathrudu
 
PDF
Notification System for Construction Logistics Application
Safe Software
 
PPTX
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
PPTX
How Can Reporting Tools Improve Marketing Performance.pptx
Varsha Nayak
 
PPTX
MiniTool Partition Wizard Crack 12.8 + Serial Key Download Latest [2025]
filmoracrack9001
 
PDF
How AI in Healthcare Apps Can Help You Enhance Patient Care?
Lilly Gracia
 
PPTX
BB FlashBack Pro 5.61.0.4843 With Crack Free Download
cracked shares
 
PDF
ESUG 2025: Pharo 13 and Beyond (Stephane Ducasse)
ESUG
 
PDF
AI Prompts Cheat Code prompt engineering
Avijit Kumar Roy
 
PDF
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
PDF
10 Salesforce Consulting Companies in Sydney.pdf
DianApps Technologies
 
PDF
Latest Capcut Pro 5.9.0 Crack Version For PC {Fully 2025
utfefguu
 
PDF
Optimizing Tiered Storage for Low-Latency Real-Time Analytics at AI Scale
Alluxio, Inc.
 
PDF
Attendance Management Software in Patna.
Camwel Solution LLP
 
PPTX
Transforming Lending with IntelliGrow – Advanced Loan Software Solutions
Intelli grow
 
PDF
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
PPT
24-BuildingGUIs Complete Materials in Java.ppt
javidmiakhil63
 
How Attendance Management Software is Revolutionizing Education.pdf
Pikmykid
 
Softaken CSV to vCard Converter accurately converts CSV files to vCard
markwillsonmw004
 
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
 
Get Started with Maestro: Agent, Robot, and Human in Action – Session 5 of 5
klpathrudu
 
Notification System for Construction Logistics Application
Safe Software
 
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
How Can Reporting Tools Improve Marketing Performance.pptx
Varsha Nayak
 
MiniTool Partition Wizard Crack 12.8 + Serial Key Download Latest [2025]
filmoracrack9001
 
How AI in Healthcare Apps Can Help You Enhance Patient Care?
Lilly Gracia
 
BB FlashBack Pro 5.61.0.4843 With Crack Free Download
cracked shares
 
ESUG 2025: Pharo 13 and Beyond (Stephane Ducasse)
ESUG
 
AI Prompts Cheat Code prompt engineering
Avijit Kumar Roy
 
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
10 Salesforce Consulting Companies in Sydney.pdf
DianApps Technologies
 
Latest Capcut Pro 5.9.0 Crack Version For PC {Fully 2025
utfefguu
 
Optimizing Tiered Storage for Low-Latency Real-Time Analytics at AI Scale
Alluxio, Inc.
 
Attendance Management Software in Patna.
Camwel Solution LLP
 
Transforming Lending with IntelliGrow – Advanced Loan Software Solutions
Intelli grow
 
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
24-BuildingGUIs Complete Materials in Java.ppt
javidmiakhil63
 

Design pattern and their application

  • 1. Design Patterns and their applications Presenter: Bui Tien Hiep
  • 2. 1. What is Design Pattern. 2. Why Design Pattern. 3. How to use Design Pattern. 4. The principle of Design Pattern 5. UML relationship 6. Gang of Four Design Pattern 7. Example apply Design Pattern in EC Contents
  • 3. "Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice“ – Pro.Christopher Alexander, University of California, Berkeley What is Design Pattern?
  • 4. Pattern = Name + Problem + Solution + Consequences What is Design Pattern?
  • 5. In general, a pattern has four essential elements: 1. The pattern name is a handle we can use to describe a design problem, its solutions, and consequences in a word or two. 2. The problem describes when to apply the pattern. It explains the problem and its context. 3. The solution describes the elements that make up the design, their relationships, responsibilities, and collaborations. 4. The consequences are the results and trade-offs of applying the pattern. What is Design Parttern?(2)
  • 6. • Good designers do not solve every problem from first principles. They reuse solutions. • Practitioners do not do a good job of recording experience in software design for others to use. Patterns help solve this problem. Why Design Pattern?
  • 7. Once you've picked a design pattern, how do you use it? Here's a step-by-step approach to applying a design pattern effectively: 1. Read the pattern once through for an overview. Pay particular attention to the Applicability and Consequences sections to ensure the pattern is right for your problem. How to Use a Design Pattern?(1) 2. Go back and study the Structure, Participants, and Collaborations sections. Make sure you understand the classes and objects in the pattern and how they relate to one another.
  • 8. 3. Look at the Sample Code section to see a concrete example of the pattern in code. Studying the code helps you learn how to implement the pattern. 4. Choose names for pattern participants that are meaningful in the application context. The names for participants in design patterns are usually too abstract to appear directly in an application. Nevertheless, it's useful to incorporate the participant name into the name that appears in the application. That helps make the pattern more explicit in the implementation. How to Use a Design Pattern?(2)
  • 9. 5. Define the classes. Declare their interfaces, establish their inheritance relationships, and define the instance variables that represent data and object references. Identify existing classes in your application that the pattern will affect, and modify them accordingly. 6. Define application-specific names for operations in the pattern. Here again, the names generally depend on the application. Use the responsibilities and collaborations associated with each operation as a guide. Also, be consistent in your naming conventions. For example, you might use the "Create-" prefix consistently to denote a factory method. 7. Implement the operations to carry out the responsibilities and collaborations in the pattern. The Implementation section offers hints to guide you in the implementation How to Use a Design Pattern?(2)
  • 10. The principle of Design Pattern The principle of one pattern can be summarized in five main points: 1. “Separate out the things that change from those that stay the same.” 2. “Program to an interface, not an implementation” 3. “Prefer composition over inheritance” 4. “Delegate, delegate, delegate.” 5. “You ain’t gonna need it”
  • 12. Gang of Four Design Patterns
  • 13. Intent: • A creational pattern dealing with creating objects without knowing their concrete class • It defines an interface for creating an object, but let the subclasses decide which class to instantiate • Useful when concrete class of object should be decided at runtime according to parameters Problem: • A framework needs to standardize the architectural model for a range of applications, but allow for individual applications to define their own domain objects and provide for their instantiation. Creational: Factory
  • 14. Intent: • Separate the construction of a complex object from its representation so that the same construction process can create different representations. • Parse a complex representation, create one of several targets Problem: • An application needs to create the elements of a complex aggregate. The specification for the aggregate exists on secondary storage and one of many representations needs to be built in primary storage. Creational: Builder
  • 15. Creational: Prototype Intent: • Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. • Co-opt one instance of a class for use as a breeder of all future instances. Problem: • Application "hard wires" the class of object to create in each "new" expression.
  • 16. Creational: Singleton Intent: • Ensure a class has only one instance, and provide a global point of access to it. • Encapsulated "just-in-time initialization" or "initialization on first use". Problem: • Application needs one, and only one, instance of an object. Additionally, lazy initialization and global access are necessary.
  • 17. Structural: Adapter Intent: • Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. • Wrap an existing class with a new interface. • Impedance match an old component to a new system Problem: • An "off the shelf" component offers compelling functionality that you would like to reuse, but its "view of the world" is not compatible with the philosophy and architecture of the system currently being developed.
  • 18. Structural: Brigde Intent: • Decouple an abstraction from its implementation so that the two can vary independently. • Publish interface in an inheritance hierarchy, and bury implementation in its own inheritance hierarchy. • Beyond encapsulation, to insulation Problem: • "Hardening of the software arteries" has occurred by using subclassing of an abstract base class to provide alternative implementations. This locks in compile-time binding between interface and implementation. The abstraction and implementation cannot be independently extended or composed.
  • 19. Structural: Composite Intent: • Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. • Recursive composition • "Directories contain entries, each of which could be a directory." • 1-to-many "has a" up the "is a" hierarchy Problem: • Application needs to manipulate a hierarchical collection of "primitive" and "composite" objects. Processing of a primitive object is handled one way, and processing of a composite object is handled differently. Having to query the "type" of each object before attempting to process it is not desirable.
  • 20. Structural: Decorator Intent: • Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. • Client-specified embellishment of a core object by recursively wrapping it. • Wrapping a gift, putting it in a box, and wrapping the box. Problem: • You want to add behavior or state to individual objects at run-time. Inheritance is not feasible because it is static and applies to an entire class.
  • 21. Structural: Proxy Intent: • Provide a surrogate or placeholder for another object to control access to it. • Use an extra level of indirection to support distributed, controlled, or intelligent access. • Add a wrapper and delegation to protect the real component from undue complexity. Problem: • You need to support resource-hungry objects, and you do not want to instantiate such objects unless and until they are actually requested by the client
  • 22. Behavioral: Chain of Responsibility Intent: • Avoid 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 request along the chain until an object handles it • Launch-and-leave requests with a single processing pipeline that contains many possible handlers. • An object-oriented linked list with recursive traversal. Problem: • There is a potentially variable number of "handler" or "processing element" or "node" objects, and a stream of requests that must be handled. Need to efficiently process the requests without hard-wiring handler relationships and precedence, or request-to-handler mappings.
  • 23. Behavioral: Command Intent: • Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. • Promote "invocation of a method on an object" to full object status • An object-oriented callback. Problem: • Need to issue requests to objects without knowing anything about the operation being requested or the receiver of the request.
  • 24. Behavioral: Observer Intent: • Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. • Encapsulate the core (or common or engine) components in a Subject abstraction, and the variable (or optional or user interface) components in an Observer hierarchy. • The "View" part of Model-View-Controller. Problem: • A large monolithic design does not scale well as new graphing or monitoring requirements are levied.
  • 25. Behavioral: Template Intent: • Define the skeleton of an algorithm in an operation, deferring some steps to client subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure. • Base class declares algorithm 'placeholders', and derived classes implement the placeholders. Problem: • Two different components have significant similarities, but demonstrate no reuse of common interface or implementation. If a change common to both components becomes necessary, duplicate effort must be expended
  • 26. Specification Design Pattern Intent: • Validation determines if a particular object satisfies a certain criteria. • Selection identifies those elements of a collection that satisfy the given criteria Problem: • Need to clean way to encapsulate business logic
  • 27. Example apply Design Pattern in EC Problem: Input: The expense list of a report and the policy list of company Output: Policy violation messages. Solution Design Pattern Description Specification Chaining the business rules together using boolean logic. Builder Create policy validation objects
  • 28. Example apply Design Pattern in EC(2)
  • 29. Example apply Design Pattern in EC(3)
  • 30. Reference 1. http://sourcemaking.com/design_patterns 2. Design Patterns: Elements of Reusable Object-Oriented Software 3. http://www.cs.colorado.edu/~kena/classes/5448/s11/lectures/ 4. http://en.wikipedia.org/wiki/Specification_pattern