Login :
Password :

Design patterns

Development of the composition on <<Composite>> without protocol conformance

Static diagram :

Static diagram

Strong points :

  1. 1. Decoupling and extensibility
    1. KO 1.1 Maximal factorization of the composition
    2. KO 1.2 Addition or removal of a leaf does not need code modification
    3. KO 1.3 Addition or removal of a composite does not need code modification
  2. 2. Uniform protocol
    1. KO 2.1 Uniform protocol on operations of composed object
    2. OK 2.2 Uniform protocol on composition managing
    3. OK 2.3 Unique access point for the client class

Spoiled pattern instantiations on different problems

Problem 1 :

Problem wording :
Design a system enabling to draw a graphic image. A graphic image is composed of lines, rectangles, texts and images. An image may be composed of other images, lines, rectangles and texts.
Optimal solution :

Static diagram :

Static diagram

This solution allows a good decoupling, and a good extensibility.

Alternative solution :

Static diagram :

Static diagram

In this solution, there is no decoupling, no extensiblity. Except for the composition managing, there is no uniform protocol

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