liveBook · Manning

Template method design pattern

The Template Method design pattern defines an algorithm's fixed sequence in a superclass while allowing subclasses to implement or customize selected steps.

How 2 Manning books explain it

Software Design for Python Programmers

The Template Method pattern defines an algorithm's fixed-order skeleton in a superclass while allowing subclasses to implement selected variable steps.

How it is used
Structures fixed-order algorithms whose common and varying steps must be maintained across related implementations.
How deep it goes
Explains the pattern through sports-report code, superclass responsibilities, subclass variation, benefits, and comparison with Strategy.
Examples
Uses baseball and volleyball game reports, with shared headers and footers and sport-specific acquisition, analysis, and printing.
What you can do after
Build it from scratch by modeling a shared algorithm in a superclass and delegating selected steps to subclasses.

Read how Software Design for Python Programmers explains template method design pattern →

Object-Oriented Software Design in C++

The Template Method Design Pattern is a behavioral design pattern that defines an algorithm's fixed sequence while allowing subclasses to vary selected steps.

How it is used
Structures report-generation algorithms whose sequence stays fixed while data handling, analysis, and presentation vary.
How deep it goes
Defines the superclass, template method, common implementations, abstract steps, and concrete report subclasses.
Examples
Uses baseball and volleyball game reports, including statistics, bar charts, winning scores, and round-by-round scoring.
What you can do after
Build an inheritance-based algorithm skeleton that preserves execution order while allowing subclasses to implement selected steps.

Read how Object-Oriented Software Design in C++ explains template method design pattern →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.