A template method contains a generic algorithm skeleton, delegates part of algorithm to abstract hook methods.

  • Hook methods are overwritten in sub-classes to provide the specifics steps.
  • Template and hook method are implemented in the same class / object.
  • Polymorphism enables variability.

Benefits:

  • Easily separate core logic and variation points.
  • Easily provide many different implementations of the details and use the one you need.

Disadvantages:

  • Variation is only supported at compile time.