Login :
Password :

Design patterns

Bad classification

Static diagram :

Static diagram

Strong points :

  1. 1. Extensibility
    1. OK 1.1 States' protocol factorization
    2. OK 1.2 Addition or removal of a state does not need code modification
  2. 2. Simplified management
    1. KO 2.1 Possibility of state modification at execution time without deletion
    2. KO 2.2 State behavior decoupling

Spoiled pattern instantiations on different problems

Problem 1 :

Problem wording :
Design a DVD market place work. The DVD market place provides DVD to its clients with three categories: children, normal and new. A DVD is new during some weeks, and after change category. The DVD price depends on the category. It is probable that the system evolves in order to take into account the horror category.
Optimal solution :

Static diagram :

Static diagram

Thanks to the inheritance links, we are able to distinct the DVD to its states. In these case, the addition of a new state does not imply code modification.

Alternative solution :

Static diagram :

Static diagram

The category is a subclass of DVD imposing instances destruction to change of category. The question of the validity of this solution is open in regard of the proposed exercise. However, we have considered this solution valid in using a prototype creational pattern with a category as parameter.

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