Creational design patterns
●● Factory Method: Allow subclasses to “decide”
	 which class to instantiate.
●● Abstract Factory: Encapsulate a set of analo-
	 gous factories that produce families of objects.
●● Builder: Encapsulate the construction of com-
	 plex objects from their representation; so, the
	 same building process can create various repre-
	 sentations by specifying only type and content.
●● Singleton:	Ensure that only a single instance of
	 a class exists and provide a single method for
	 gaining access to it.
●● Prototype: Create an initialized instance for
	 cloning or copying.
Factory Method
Provide an interface for the creation of objects.
Allow subclasses to “decide” which class to instantiate.
c
Abstract Factory
Povide an interface for creating families of related
or dependent objects. A factory for factories.
c
Builder
Seperate the construction process (how) of a complex object
from the concrete representations (what).
c
Singleton
Ensure a class only has one instance, and provide a global
point of access to it.
Oh, I’m so
loooooooonly
c
Prototype
Make variations on copies of a basic-object.
COPY-SERVICE
c
Structural design patterns
●● Adapter: Adapt an interface to an expected
	 interface.
●● Bridge: Decouple an interface from its
	 implementation.
●● Composite: Create a tree structure for
	 part-whole hierarchies.
●● Decorator: Extend functionality dynamically.
●● Facade: Simplify usage by defining a high-level
	 interface.
●● Flyweight: Support fine-grained objects
	 efficiently by sharing.
●● Proxy: Represent an object with another object
	 for access control.
Adapter (= Wrapper)
Adapt an interface to an expected interface.c
Bridge
Decouple an abstraction from its implementation.c
COLA
COLA
COLA
COLA
1 LITER
1 LITER
COLA
MILK
MILK
1 LITER
1 LITER
MILK
Composite
Create a tree structure for part-whole hierarchies. A node is also a
(part of a) tree. Recursive:
c
Decorator
Add extra functionallity (at runtime),
while keeping the interface the same.
Matroushka’s...
c
Facade
Provide a general (simpler) interface for a set of interfaces.
looks
simple
c
Flyweight
Use one instance of a class to provide many
“virtual” instances.
c
Proxy
Provide a surrogate or placeholder for another object
to control access to it.
c
Behavioral design patterns
●● Chain of Responsibility: Define a method of passing a
request among a chain of objects.
●● Command: Encapsulate a command request in an object.
●● Interpreter: Allow inclusion of language elements in an appli-
cation.
●● Iterator: Enable sequential access to collection elements.
●● Mediator: Define simplified communication between classes.
●● Memento: Save and restore the internal state of an object.
●● Observer: Define a scheme for notifying objects of changes to
another object.
●● State: Alter the behavior of an object when its state changes.
●● Strategy: Encapsulate an algorithm inside a class.
●● Template Method: Allow subclasses to redefine the steps of
an algorithm.
●● Visitor: Define a new operation on a class without changing it.
Command
Encapsulate a command request in an object.c
YOU,DO YOUR
TASK!
LIGHT
OFF
LIGHT
ON
TASKTASK
Chain of Responsibility
Define a method of passing a request among a chain of objects.c
Interpreter
Domain -> (little) language -> grammar -> objects
(DSL)
he means:
do this, do that,
and after finishing it,
go there!
HÉ!HÉ!
c
Iterator
Enable sequential access to collection elements, without showing
the underlying data-structures (array, list, records, etc)
nextnext
next
c
Mediator
Layer in between: communication via one object.c
Memento
Save and restore the internal state of an object.
ME
c
Observer
Notify “subscribers” of changes.
WHO?
ME
ME
MENO
c
State
Let an object show other methods after a change of internal
state (as if it changes it’s class).
in a.....hick......different state,
....hick....I behave differently....hick.....
c
Strategy
When something can be done in several ways, make those
ways interchangeable.
POSSI-
BILITIES
c
Template Method
The skeleton of an algorithm is fixed, but parts can be filled in
differently.
c
Visitor
Make a kind of plugin-possibility for methods: in that way me-
thods can be added in runtime.
printservice!
c
extra: Mixin
●● Used in Nooku (and a.o. in Ruby and Python)
●● a kind of abstract class that is mixed into another object
●● all methods of the mixin are now part of the object
●● handle with care: beware of tight coupling....

Designpatterns illustrated

  • 1.
    Creational design patterns ●●Factory Method: Allow subclasses to “decide” which class to instantiate. ●● Abstract Factory: Encapsulate a set of analo- gous factories that produce families of objects. ●● Builder: Encapsulate the construction of com- plex objects from their representation; so, the same building process can create various repre- sentations by specifying only type and content. ●● Singleton: Ensure that only a single instance of a class exists and provide a single method for gaining access to it. ●● Prototype: Create an initialized instance for cloning or copying.
  • 2.
    Factory Method Provide aninterface for the creation of objects. Allow subclasses to “decide” which class to instantiate. c
  • 3.
    Abstract Factory Povide aninterface for creating families of related or dependent objects. A factory for factories. c
  • 4.
    Builder Seperate the constructionprocess (how) of a complex object from the concrete representations (what). c
  • 5.
    Singleton Ensure a classonly has one instance, and provide a global point of access to it. Oh, I’m so loooooooonly c
  • 6.
    Prototype Make variations oncopies of a basic-object. COPY-SERVICE c
  • 7.
    Structural design patterns ●●Adapter: Adapt an interface to an expected interface. ●● Bridge: Decouple an interface from its implementation. ●● Composite: Create a tree structure for part-whole hierarchies. ●● Decorator: Extend functionality dynamically. ●● Facade: Simplify usage by defining a high-level interface. ●● Flyweight: Support fine-grained objects efficiently by sharing. ●● Proxy: Represent an object with another object for access control.
  • 8.
    Adapter (= Wrapper) Adaptan interface to an expected interface.c
  • 9.
    Bridge Decouple an abstractionfrom its implementation.c COLA COLA COLA COLA 1 LITER 1 LITER COLA MILK MILK 1 LITER 1 LITER MILK
  • 10.
    Composite Create a treestructure for part-whole hierarchies. A node is also a (part of a) tree. Recursive: c
  • 11.
    Decorator Add extra functionallity(at runtime), while keeping the interface the same. Matroushka’s... c
  • 12.
    Facade Provide a general(simpler) interface for a set of interfaces. looks simple c
  • 13.
    Flyweight Use one instanceof a class to provide many “virtual” instances. c
  • 14.
    Proxy Provide a surrogateor placeholder for another object to control access to it. c
  • 15.
    Behavioral design patterns ●●Chain of Responsibility: Define a method of passing a request among a chain of objects. ●● Command: Encapsulate a command request in an object. ●● Interpreter: Allow inclusion of language elements in an appli- cation. ●● Iterator: Enable sequential access to collection elements. ●● Mediator: Define simplified communication between classes. ●● Memento: Save and restore the internal state of an object. ●● Observer: Define a scheme for notifying objects of changes to another object. ●● State: Alter the behavior of an object when its state changes. ●● Strategy: Encapsulate an algorithm inside a class. ●● Template Method: Allow subclasses to redefine the steps of an algorithm. ●● Visitor: Define a new operation on a class without changing it.
  • 16.
    Command Encapsulate a commandrequest in an object.c YOU,DO YOUR TASK! LIGHT OFF LIGHT ON TASKTASK
  • 17.
    Chain of Responsibility Definea method of passing a request among a chain of objects.c
  • 18.
    Interpreter Domain -> (little)language -> grammar -> objects (DSL) he means: do this, do that, and after finishing it, go there! HÉ!HÉ! c
  • 19.
    Iterator Enable sequential accessto collection elements, without showing the underlying data-structures (array, list, records, etc) nextnext next c
  • 20.
    Mediator Layer in between:communication via one object.c
  • 21.
    Memento Save and restorethe internal state of an object. ME c
  • 22.
    Observer Notify “subscribers” ofchanges. WHO? ME ME MENO c
  • 23.
    State Let an objectshow other methods after a change of internal state (as if it changes it’s class). in a.....hick......different state, ....hick....I behave differently....hick..... c
  • 24.
    Strategy When something canbe done in several ways, make those ways interchangeable. POSSI- BILITIES c
  • 25.
    Template Method The skeletonof an algorithm is fixed, but parts can be filled in differently. c
  • 26.
    Visitor Make a kindof plugin-possibility for methods: in that way me- thods can be added in runtime. printservice! c
  • 27.
    extra: Mixin ●● Usedin Nooku (and a.o. in Ruby and Python) ●● a kind of abstract class that is mixed into another object ●● all methods of the mixin are now part of the object ●● handle with care: beware of tight coupling....