KEMBAR78
Design Patterns in Object Oriented Design | PDF
Design Patterns
●
Creational
Patterns
●
Structural
Patterns
●
Behavioural
Patterns
Design Patterns
Guess the object
It's a hefty land vehicle, typically with
multiple axles and large, robust tires. Its
defining feature is a separate articulated
section at the rear, designed for carrying
substantial loads. This trailing portion
often appears as a large box or open
platform
Creational Patterns
How objects get created
Abstract Factory
Light Theme Dark Theme
Abstract Factory
●
Create sets or families of related objects
Abstract Factory
Builder Pattern
Builder Pattern
●
For objects that need many options for
creation
●
Avoid creating large constructors
●
Fine tuned object creation
Builder Pattern
Factory Method
Factory Method
●
Let a class defer the instantiation of an
object to it’s subclass
●
Useful if multiple subclasses need similar
objects with slightly different features
●
Decouples the creation of an object from its
usage
Factory Method
Prototype
Prototype
●
Create new objects by cloning existing ones
●
Performant
●
Avoid sub classing
Prototype
Singleton
Singleton
●
Ensure a class has only one instance
●
Provide single global access
Singleton
Structural Patterns
Putting objects together
Adapter
Adapter
●
When a target interface doesn’t match the
client interface
●
Sits in the middle of a target and client
Bridge
Shape
Bridge
●
Decoupling abstraction from implementation
●
Two separate class hierarchies
– Abstraction : What
– Implementation : How
●
Useful when abstraction and implementation
wants to change independently
Bridge
Composite
Composite
●
Tree structures
●
Perform same operation on single leaf or
entire branch
Composite
Composite
Decorator
Decorator
●
Dynamically add responsibilities and behaviours
to objects
●
Decorator takes an instance of an interface or
another decorator in the constructor
●
When a method is called it does something and
pass the call to wrapped object
●
External users still call the interface, doesn’t
know how many layers it has
Decorator
Façade
●
Provide a single unified simple interface for a
larger complex subsystem
●
Client depend only on the Façade
Façade
Flyweight
Flyweight
●
Support huge number of fine tuned objects
●
Separate state into two types
– Intrinsic state : Invariant / Sharable
– Extrinsic state : Variable / Depend on context
●
One flyweight object carrying intrinsic state
shared by all objects
Flyweight
Proxy
Proxy
●
Acts as a placeholder for another object
●
Controls access and Intercept calls
●
Has the same interface as the target
Proxy
Behavioural Patterns
How objects interact
Chain of Responsibility
Customer
Customer
Care
Technical
Tier 1
Technical
Tier 2
Management
Chain of Responsibility
●
When a lot of receivers can solve a request,
but sender doesn’t have to know which one
to send
●
Create a chain of receiver objects
Chain of Responsibility
Command
Command
●
Separate request for an action from
implementation
●
Wraps request into command object
Command
Interpreter
Interpreter
●
Create grammar for language and
understand it
●
Expression class hierarchy
●
Recursive
Interpreter
Iterator
●
Iterate without knowing implementation
Mediator
Mediator
●
Avoid direct communication
●
All calls go through mediator
●
Promote loose coupling
Mediator
Mediator
Memento
Memento
●
Capture object’s internal state without
breaking encapsulation
●
Knows how to create and restore objects
Memento
Observer
Observer
●
Manage one to many dependencies
●
When state changes, all observers get
notified
●
Observers register with subject, subject
keeps a list of observers
Observer
State Pattern
State Pattern
●
When objects behaviour changes according
to internal state
●
Avoid using if statements
●
Encapsulate behaviours into state objects
State Pattern
Strategy Pattern
Strategy Pattern
●
When there are multiple strategies to do
some task
●
Encapsulate all algorithms into separate
strategy objects
●
Open for extension, closed for modification
Strategy Pattern
Template Method
Template Method
●
Write a template algorithm in a base class,
subclasses override it
●
A sequence of methods that individually can
be overridden
Template Method
Visitor
Visitor
●
Perform operations on objects without
changing their classes
●
Visitor has .accept() method
●
Element opens the door, visitor comes in and
does the work according to type.
Visitor
Thank You
Bottom Text

Design Patterns in Object Oriented Design