Object-Oriented Programming: Design Patterns: Ma. Diane S. Rivera
Object-Oriented Programming: Design Patterns: Ma. Diane S. Rivera
Programming:
Design Patterns
Ma. Diane S. Rivera
[email protected]
Main Categories
1. Creational 2. Structural 3. Behavioral
• separates the
construction of a
complex object from its
representation so that
the same construction
process can create
different representations
• creates an instance of
several families of
classes
• useful in situations that
require creation of many
different types of objects,
all derived from a
common base type
• declares an abstract
base class that specifies
a pure virtual “clone”
method, and maintains a
dictionary of all
“clonable” concrete
derived classes.
• Implementation: Declare
an abstract base class
that specifies a pure
virtual clone() method
• decouples an abstraction
from its implementation
so that the two can vary
independently
• synonym for the
"handle/body" idiom
• interface object is the
"handle" and
implementation class is
the "body"
• adds responsibilities to
objects dynamically
• provides flexible
alternative to
subclassing for
extending functionality
• client-specified
embellishment of a core
object by recursively
wrapping it
• provides a unified
interface to a set of
interfaces in a
subsystem.
• defines a higher-level
interface that makes the
subsystem easier to use
• provides a surrogate or
placeholder for another
object to control access
to it
• uses an extra level of
indirection to support
distributed, controlled, or
intelligent access
• encapsulates a
command request as an
object thereby letting you
parameterize clients with
different requests, queue
or log requests, and
support undoable
operations
• defines simplified
communication between
classes
• defines an object that
encapsulates how a set
of objects interact
• promotes loose coupling
by keeping objects from
referring to each other
explicitly; lets you vary
their interaction
independently
• a way of notifying
change to a number of
classes
• define a one-to-many
dependency between
objects so that when one
object changes state, all
its dependents are
notified and updated
automatically
• defines a family of
algorithms, encapsulates
each one, and make one
interchangeable
• lets the algorithm vary
independently from the
clients that use it
• capture the abstraction
in an interface, bury
implementation details in
derived classes
Flyweight
• a fine-grained instance used for efficient sharing
• uses sharing to support large numbers of fine-grained objects efficiently
(cache and reuse existing class instances)
• pattern for saving memory
Interpreter
• given a language, define a representation for its grammar along with an
interpreter that uses the representation to interpret sentences in the
language
• same with composite pattern only with different application or intent
Memento
• without violating encapsulation, capture and externalize an object's
internal state so that the object can be returned to this state later
• promotes undo or rollback to full object status
Visitor
• defines a new operation to a class without changing the classes of the
elements on which it operates; makes use of double dispatch
• technique for recovering lost type information