Design Patterns Design Patterns
By Mareck Kortylevitch and By Mareck Kortylevitch and
Piotreck Ratchinsky
Piotreck Ratchinsky
What is Design Pattern?
What is Design Pattern?
Recurring solution to known Recurring solution to known problems
problems
Workaround to problems that Workaround to problems that
arise when developing software arise when developing software
within a particular context
within a particular context
History History
Precursor of design pattern was Precursor of design pattern was Christopher Alexander
Christopher Alexander
First Design Patterns used in First Design Patterns used in architecture
architecture
Why to use DP?
Why to use DP?
Help you learn from others' Help you learn from others'
successes instead of your own successes instead of your own
failures failures
Provide a communication Provide a communication
platform concerning elegant, platform concerning elegant,
reusable solutions to commonly reusable solutions to commonly
encountered programming encountered programming
challenges
challenges
Why to use...continuation Why to use...continuation
Enforce using techspeak Enforce using techspeak
Isolate changes in the code Isolate changes in the code
Design and interaction of Design and interaction of objects
objects
Design Patterns Examples Design Patterns Examples
Facade Facade
Adapter Adapter
Singleton Singleton
Abstract Factory Abstract Factory
Bridge Bridge
Facade - definition Facade - definition
Provide a unified interface to a Provide a unified interface to a set of interfaces in a subsystem.
set of interfaces in a subsystem.
Façade defines a higher-level Façade defines a higher-level
interface that makes the interface that makes the
subsystem easier to use.
subsystem easier to use.
Facade -
Facade - UML class diagram UML class diagram
Facade - example Facade - example
Facade Facade (MortgageApplication) (MortgageApplication)
knows which subsystem classes are knows which subsystem classes are responsible for a request.
responsible for a request.
delegates client requests to appropriate delegates client requests to appropriate subsystem objects.
subsystem objects.
Subsystem classes Subsystem classes (Bank, (Bank, Credit, Loan)
Credit, Loan)
implement subsystem functionality. implement subsystem functionality.
handle work assigned by the Facade handle work assigned by the Facade object.
object.
have no knowledge of the facade and have no knowledge of the facade and
Facade – example diagram Facade – example diagram
Facade
Subsystems
Loan Credit
Bank
Singleton - definition Singleton - definition
ensure a class has only one instance ensure a class has only one instance and provide a global point of access and provide a global point of access
to it.
to it.
defines an Instance operation that defines an Instance operation that lets clients access its unique
lets clients access its unique instance. Instance() is a class instance. Instance() is a class
operation.
operation.
responsible for creating and responsible for creating and
maintaining its own unique instance.
maintaining its own unique instance.
Singleton – UML Singleton – UML
Singleton