Design Patterns
Design Patterns
Creational Patterns
- Deal with initializing and configuring of classes
and objects
Structural Patterns
- Deal with decoupling interface and
implementation of classes and objects
Behavioral Patterns
- Deal with dynamic interactions among societies
of classes and objects
Design Patterns Space
Purpose
Creational Structural Behavioral
Class Factory Adapter Interpreter
Method
Abstract Adapter Chain of
Factory Bridge Responsibility
Builder Composite Command
Prototype Decorator Iterator
Scope Singleton Facade Mediator
Object Flyweight Memento
Proxy Observer
State
Strategy
Visitor
How Patterns are Described
private constructor
private constructor doesn’t allow us to
create object in main()
static Keyword
static properties are shared among
objects
Use Façade to define the sequence of method calls and use Façade object to
do all the stuff
Facade - Code
Facade - Code
Facade - Code
Builder
Problem:
To initialize properties we have to remember the
sequence given in constructor. How to do
initialization without remembering sequence?
Number of parameters in constructor call must be
equal to number of parameters in constructor
definition. How to avoid it?
Solution:
Use Builder to build object and return it to the
main()
Builder - Code
Builder – Code (The Problem)