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.
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
- design patternkind of · A design pattern is a reusable, general solution structure for a recurring software design problem in a particular context.
- inheritanceuses · Inheritance is a mechanism by which a child type or element receives properties, values, or behavior from a parent, subject to system rules and possible overrides.
- machine learninguses · Machine learning is a field of computational methods in which systems learn patterns or relationships from data to make predictions, decisions, or other outputs.
- strategy design patterncontrasts with · The Strategy design pattern encapsulates interchangeable algorithms or behaviors behind a common interface so they can be selected independently of the code that uses them.
- callbackuses · A callback is a function or other callable supplied to software for invocation later in response to a specified event, condition, or point in execution.
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.

