Design Patterns Lecture
Design Patterns Lecture
Reduce gap
Design Implementation
Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design patterns: elements of reusable
object-oriented software. 1995.
Buschmann, F., Meunier, R., Rohnert, H., Sommerlad, P., Stal, M.: Pattern-oriented
software architecture: a system of patterns. 2002.
Design patterns you have already seen
Encapsulation (Data Hiding)
Subclassing (Inheritance)
Iteration
Exceptions
Encapsulation pattern
Problem: Exposed fields are directly
manipulated from outside, leading to
undesirable dependences that prevent
changing the implementation.
Provide a unified
interface to a set
of interfaces in a
subsystem.
Facade (Software counterpart)
Flyweight (Non software example)
Use sharing to
support large
numbers of fine-
grained objects
efficiently
Flyweight (Software counterpart)
Memory
Chain of Responsibility (Non software
example)
Chain the
receiving objects
and pass the
request along the
chain until an
object handles it.
Chain of Responsibility (Software
counterpart)
Internet
Externalize
object’s state so
that object can be
restored to this
state later.
Memento (Software counterpart)
Observer (Non software example)
When an object
changes its state,
all its dependants
are notified.
Observer (Software counterpart)
Internet
Cricinfo
Server
Adapter (Non software example)
Convert the
interface of a
class into another
Interface clients
expect.
Adapter (Software counterpart)
Java Native
Java module C++ module
Interface (JNI)
Builder (Non software example)
Java Compiler
Python Compiler
Provide a way to
access the
elements of a set
sequentially.
Iterator (Software counterpart)
Interpreter (Non software example)
Interpreter interprets
the sentences in a
language based
on its grammar.
Interpreter (Software counterpart)
In Gtalk/Yahoo messengers
:-) is interpreted as
:-( is interpreted as
Broker (Non software example)
Broker component is
responsible for
coordinating
communication
between clients and
remote servers.
Broker (Software counterpart)
Publisher-Subscriber (Non software
example)
Publishers register
themselves to a
broker and
subscribers discover
publisher from broker.
Publisher-Subscriber (Software
counterpart)
Forums (e.g. movie forums)
Proxy (Non software example)
Provide a surrogate or
placeholder for
another object to
control access to it.
Proxy (Software counterpart)
Strategy (Non software example)
Multiple
interchangeable
weapons available to
attack an enemy.
Mediator (Non software example)
Loose coupling
between colleague
objects is achieved by
having colleagues
communicate with the
Mediator, rather than
one another.
Mediator (Software counterpart)
Gtalk Server
Master-Slave (Non software example)
Master component
distributes work to
identical slave
components and
computes a final
result from the results
when the slaves
return.
Master-Slave (Software counterpart)
Movie players High-resolution Game players
Graphics
partitioning
Layers (Software example)