What is the Template Method Pattern?

Updated Apr 28, 2026

Short answer

A behavioral pattern that defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure.

Deep explanation

The template method is defined in an abstract class and calls specific abstract or virtual methods. Subclasses implement these steps, but the overall sequence is locked by the template method.

Real-world example

A document generation process where opening/saving is identical, but generating PDF vs HTML is delegated to subclasses.

Common mistakes

  • Allowing subclasses to override the template method itself, destroying the skeleton of the algorithm.

Follow-up questions

  • What is a 'hook' in the Template Method pattern?

More Design Patterns interview questions

View all →