Login :
Password :

Design patterns

Decorator

Static diagram :

Static diagram

Description :

Type :  St  (Structural)
Intent : Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
Applicability : Use Decorator :
- to add responsibilities to individual objects dynamically and transparently, that is, without affecting other objects.
- for responsibilities that can be withdrawn.
- when extension by subclassing is impractical. Sometimes a large number of independent extensions are possible and would produce an explosion of subclasses to support every combination. Or a class definition may be hidden or otherwise unavailable for subclassing.

Strong points :

  1. 1. Extensibility
    1. 1.1 Addition or removal of a decorator does not need code modification
    2. 1.2 Addition or removal of an object to decorate does not need code modification
  2. 2. Decoupling between decorator objects and objects to decorate
    1. 2.1 Minimal number of «Decorator» classes
    2. 2.2 Maximal factorization between decorators and object to decorate
  3. 3. Decorators managing on program execution
    1. 3.1 Objects to decorate have any knowledge on decorators
    2. 3.2 A decorator may be decorated by another decorator

Pattern's participants :

Spoiled patterns :

  1. 1. Development on <<Decorator>>
  2. 2. Development on <<Decorator>> without uniform protocol
  3. 3. Misdecoupling
  4. 4. Maximal development on <<Component>>
  5. 5. Development of decorations on <<Component>>
  6. 6. Misdecoupling without extension possibility on <<Component>>
  7. 7. Development on <<Decorator>>

Problems :

  1. 1. Recursive objects decoration
Les têtes de mule
Cédric BOUHOURS
Cédric BOUHOURS
Cédric BOUHOURS