Skip to content
Commitwise
Menu

Template Method pattern

A base class method that runs fixed steps in a fixed order and lets subclasses supply only the steps that differ.

Definition

The template method itself is final; it calls abstract methods (steps every subclass must implement) and hooks (optional steps with a default). Framework lifecycle methods such as viewDidLoad and onCreate are steps in templates owned by the framework. When variants need to be combined or chosen at runtime, passing the varying step as a function or Strategy is usually better than inheritance.

In practice

ContactImporter.run parses, validates, saves and reports; CsvContactImporter only implements parse.

Related terms

Esc

Type to search the whole site.