Tuesday, 26 April 2016

The toolbox pattern

If a carpenter wants to build a cabinet, then he collects base materials (wood, nails, paint), opens his toolbox, and starts working. He may use a hammer, a saw, a drill, a screwdriver, a measure stick, painting brush, etc. 
Let's attempt to write the steps of the use case to build a cabinet:
  1. Get the base materials
  2. Use tools to make wooden parts
  3. Put the parts together
  4. Paint the cabinet
Not correct: the steps are not necessarily done in this sequence - the carpenter could paint the wood before putting the parts together. (BTW: As a scenario it would be OK.)
Attempt 2:
  1. Get materials
  2. Use tools
Not correct. The carpenter could get some material, start working with his tools, then collect some more materials.
Attempt 3:
  1. Make cabinet.
Correct. This is a correct use case, but it is not very useful...
Why is this so? All actions performed with the tools from the toolbox may or may not occur, and in any given sequence, repeatedly or not. This I call the toolbox pattern.

No comments:

Post a comment