Login :
Password :

Design patterns

Recursive objects decoration

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 1 :

Static diagram :

Static diagram

Except for adding a new Decorator, this solution is not so bad

Click here to see the spoiled pattern deduced from this alternative solution

Alternative solution 2 :

Static diagram :

Static diagram

In this solution, there is no extensibility possibilities, no maximal factorisation between decorators and objects to decorate, and a decorator can't be decorated by another decorator

Click here to see the spoiled pattern deduced from this alternative solution

Alternative solution 3 :

Static diagram :

Static diagram

In this solution, we cannot manage the decoration during the execution.

Click here to see the spoiled pattern deduced from this alternative solution

Alternative solution 4 :

Static diagram :

Static diagram

In this solution, it is not possible to add or to remove a object to decorate withtout doing code mofication. The factorisation between decorators and objects to decorate is not maximal. Moreover, a decorator cannot be decorated by another decorator.

Click here to see the spoiled pattern deduced from this alternative solution

Alternative solution 5 :

Static diagram :

Static diagram

This solution cannot manage the decoration during the execution, and there is some problems concerning the extensibility and the decoupling.

Click here to see the spoiled pattern deduced from this alternative solution

Alternative solution 6 :

Static diagram :

Static diagram

This solution presents problems on decoupling and extensibility.

Click here to see the spoiled pattern deduced from this alternative solution

Alternative solution 7 :

Static diagram :

Static diagram

This solution is not so bad, except for the decoration of a decorator.

Click here to see the spoiled pattern deduced from this alternative solution

Les têtes de mule
Cédric BOUHOURS
Cédric BOUHOURS
Cédric BOUHOURS