Same Steps, One Step Different

Same Steps, One Step Different: Template Method: Same Routine, Your Own Step, Strategy or Template Method?.

Updated

  1. Template Method: Same Routine, Your Own Step (Journeyman): When three label classes copy the same four steps and differ only in the barcode, a fix to the shared steps has to be made three times, and one copy is always missed; writing the routine once in a base class and letting each carrier's subclass fill in its own barcode is the Template Method pattern.
  2. Strategy or Template Method? (Journeyman): Strategy and Template Method both let one step of a routine vary: Strategy hands the step in as an object or function (has-a), Template Method leaves it for a subclass to fill in (is-a); a look-alike table, a run-time change and a second varying step show what each costs, and why most teams reach for Strategy first.