Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

Overview of Design Patterns

&
The Builder Design Pattern
Design Patterns
A pattern is a proven solution to a problem in a
context.
Each pattern is a three-part rule which expresses a
relation between a certain context, a problem, and a
solution.
Design patterns represent a solutions to problems that
arise when developing software within a particular
context.
i.e Patterns = problems.solution pairs in a context
Background
Search for recurring successful designs emergent
designs from practice (via trial and error)
Supporting higher levels of reuse (i.e., reuse of
designs) is quite challenging
Described in Gama, Helm, Johnson, Vlissides 1995
(i.e., gang of 4 book)
Based on work by Christopher Alexander (an Architect)
on building homes, buildings and towns.
Design pattern use a consistent documentation
approach
Design pattern are granular and applied at different
levels such as frameworks, subsystems and sub-
subsystems
Categorizing Pattern
Patterns, then, represent expert solutions to
recurring problems in a context and thus have
been captured at many levels of abstraction
and in numerous domains. Numerous
categories are:

Creational
Structural
Behavioral

Creational Design Patterns
Abstract Factory:
Factory for building related objects
Builder:
Factory for building complex objects incrementally
Factory Method:
Method in a derived class creates associates
Prototype:
Factory for cloning new instances from a prototype
Singleton:
Factory for a singular (sole) instance

Structural Design Patterns
Adapter:
Translator adapts a server interface for a client
Bridge:
Abstraction for binding one of many implementations
Composite:
Structure for building recursive aggregations
Decorator:
Decorator extends an object transparently
Facade:
Simplifies the interface for a subsystem
Flyweight:
Many fine-grained objects shared efficiently.
Proxy:
One object approximates another

Behavioral Design Patterns
Chain of Responsibility:
Request delegated to the responsible service provider
Command:
Request is first-class object
Iterator:
Aggregate elements are accessed sequentially
Interpreter:
Language interpreter for a small grammar
Mediator:
Coordinates interactions between its associates
Memento:
Snapshot captures and restores object states privately

Behavioral Design Patterns
(Cont..)
Observer:
Dependents update automatically when subject changes
State:
Object whose behavior depends on its state
Strategy:
Abstraction for selecting one of many algorithms
Template Method:
Algorithm with some steps supplied by a derived class
Visitor:
Operations applied to elements of a heterogeneous
object structure

Builder Design
Pattern
Builder Design Pattern
Separates the construction of a complex
object from its representation
Same construction process can create
different representations

Builders specify abstract interfaces for
creating parts of a Product object
Participants in Builder Pattern
Builder : This is an interface which is used to define all the steps
to create a product
ConcreteBuilder :This is a class which implements the Builder
interface to create complex product.
Director :This is a class which is used to construct an object using
the Builder interface.
Product : This is a class which defines the parts of the complex
object which are to be generated by the builder pattern
Structure

Collaborations
The client creates the Director object and
configures it with the desired Builder object.
Director notifies the builder whenever a part
of the product should be built.
Builder handles requests from the director
and adds parts to the product.
The client retrieves the product from the
builder.

When to use it?
Need to create an object in several steps (a
step by step approach).
The creation of objects should be
independent from the way the object's parts
are assembled.
Runtime control over the creation process is
required.

You might also like