Template Method


Usage

  • Defer the exact steps of an algorithm to a subclass
  • Define the skeleton of an algorithm in an operation, deferring some steps to subclasses
  • Let subclasses redefine certain steps of an algorithm without changing the algorithm's structure

Diagram

Template Method

Participants

AbstractClass
  • Defines abstract primitive operations that concrete subclasses define to implement steps of an algorithm
  • Implements a template method defining the skeleton of an algorithm
  • The template method calls primitive operations as well as operations defined in AbstractClass or those of other objects
ConcreteClass
  • Implements the primitive operations ot carry out subclass-specific steps of the algorithm
Resources URL: 
notes/design_patterns/resources
Sources URL: 
notes/design_patterns/sources

See Also