Login :
Password :

Design patterns

Partially reification of command

Static diagram :

Static diagram

Strong points :

  1. 1. Extensibility
    1. KO 1.1 Addition or removal of a command does not need code modification
    2. KO 1.2 Commands' protocol factorization
  2. 2. Uniform protocol
    1. OK 2.1 Unique access point for the command execution
  3. 3. Recording facilities
    1. KO 3.1 Facilities in command recording

Spoiled pattern instantiations on different problems

Problem 1 :

Problem wording :
Design a tutorial to learn how to program a calculator. This calculator executes the four basic arithmetic operations. The goal of this tutorial is to make it possible to take a set of operations to be executed sequentially. The tutorial presents a button by arithmetic operation, and two input fields for the operands. After each click on a button of an operation, the user has then the choice to start again or execute the suite of operations to obtain the result. It is probable that this teachware evolves in order to make it possible to the user to remove the last operation of the list and to take into account the operation of modulo.
Optimal solution :

Static diagram :

Static diagram

A classical instantiation of the pattern.

Alternative solution :

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.

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