liveBook · Manning

Template method design pattern

Also called template method pattern

The Template Method design pattern defines an algorithm’s structure and sequence of steps while allowing selected steps to be implemented or customized by subclasses.

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 →

Also covered in

What to know first

Related concepts

Questions about template method design pattern

What is template method design pattern?

The Template Method design pattern defines an algorithm’s structure and sequence of steps while allowing selected steps to be implemented or customized by subclasses.

Which Manning books explain template method design pattern?

Software Design for Python Programmers and Object-Oriented Software Design in C++.

What should I know before learning template method design pattern?

Manning books that teach template method design pattern usually introduce code duplication, design pattern, don't repeat yourself principle and inheritance first.

What is template method design pattern a kind of?

Template method design pattern is a kind of design pattern. A design pattern is a reusable, general solution structure for a recurring software design problem.

What is template method design pattern also called?

Template method design pattern is also called template method pattern.

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.