Login :
Password :

Design patterns

Misdecoupling without extension possibility on <<Component>>

Class diagram :

Class diagram

Strong points :

  1. 1. Extensibility
    1. OK 1.1 Addition or removal of a decorator does not need code modification
    2. KO 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. OK 2.1 Minimal number of «Decorator» classes
    2. OK 2.2 Maximal factorization between decorators and object to decorate
  3. 3. Decorators managing on program execution
    1. OK 3.1 Objects to decorate have any knowledge on decorators
    2. KO 3.2 A decorator may be decorated by another decorator

Spoiled pattern instantiations on different problems

Problem 1 :

Problem wording :
Design a system enabling to display visual objects on a screen. A visual object can be composed with one or more texts or images. If needed, the system must allow to add to this object a vertical scrollbar, an horizontal scrollbar, an edge and a menu (these additions may be cumulated).
Optimal solution :

Static diagram :

Static diagram

In this solution, if we add a new decoration, there is no code modification. Moreover, the decorators are able to decorate themselves.

Alternative solution :

Static diagram :

Static diagram

This solution presents problems on decoupling and extensibility.

Les têtes de mule