Login :
Password :

Design patterns

Action encapsulation

Problem wording :

In order to animate lights during a show, a light console is used to switch on or off lights or devices (such as a smoke machine). The memorization of ignition or extinction sequences is important to the dynamism of the show. So model the possibility for a light console to chain actions on lights or a smoke machine.

Optimal solution :

Static diagram :

Static diagram

A classical instantiation of the pattern.

Alternative solution 1 :

Static diagram :

Static diagram

This solution grants all the management to the System class but separates the real operation in different classes. So, the solution is valid, but imposes a lot of communications between the System class and the operations classes. Moreover, System does not memorize the operation but an identifier from OperationType. So, the System class must test all the identifiers during the computeOperation that is problematic if there are a lot of operations.

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