Template Method Pattern

Summary

  • The Template Method pattern enables algorithms to defer certain steps to subclasses.

Class diagram: (see Template Method Pattern code review)

Template Method Pattern class diagram of sample code download

Usage

Use the Template Method pattern when:

  • Common behaviour can be factored out of an algorithm.
  • The behaviour varies according to the type of a subclass.