Behavioral pattern · Visual logic

Template Method: Freeze the Sequence, Vary the Steps

Template Method defines a stable algorithm sequence while allowing selected steps to vary through subclass hooks or overrides.

Problem

Several workflows share the same sequence but duplicate orchestration because a few steps differ by case.

Rule

Keep the invariant algorithm in one template method and expose only intentional variation points to specialized implementations.

Run
  1. TEMPLATE executes the shared sequence in a controlled order.
  2. FIXED STEPS enforce invariants that every workflow must preserve.
  3. HOOKS let specialized implementations vary selected operations only.
Output

Related workflows reuse one verified sequence while customizing only the parts designed to change.

Run it in the real world

A data import pipeline always validates, parses, normalizes, and stores, while CSV and JSON importers override only parsing.

Go deeper

This is an original explanation and example inspired by Head First Design Patterns. The book covers the complete pattern, design principles, and implementation detail.

Retail links are not affiliate links yet. If that changes, this page will clearly disclose it.