Skip to content
StackDecode
System Design
15. Software Design PatternsAnimated walkthrough

Template Method Pattern

Fix the skeleton, let subclasses fill in steps.

The idea

A base class defines the algorithm order, and subclasses override specific steps.

Watch it work

The steps light up one at a time. Use the controls to pause or step through.

  1. 1Define the algorithm in a base class
  2. 2Mark steps to override
  3. 3Subclasses implement steps
  4. 4Run the template
1/4

Step by step

  1. 1Define the algorithm in a base class
  2. 2Mark steps to override
  3. 3Subclasses implement steps
  4. 4Run the template

Where it is used

Frameworks.

Watch out for

Inheritance couples the subclass tightly.

Related