The Template Method pattern is a behavioral GoF design pattern by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides that defines the skeleton of an algorithm in an operation and defers some steps to subclasses. The invariant parts are implemented once in a common class, while subclasses supply the varying steps, as in a report generator whose sequence of loading, transforming and formatting stays fixed.
GoF-Template Method Pattern
Details
- Full Name
-
GoF Template Method Pattern (Behavioral)
Intent:
Define the skeleton of an algorithm in an operation, deferring some steps to subclasses.
When to Use:
-
When you want to implement the invariant parts of an algorithm once and leave it to subclasses to implement varying behavior
-
When common behavior among subclasses should be factored and localized in a common class
Prompt Example:
"Refactore die Report-Generierung nach dem GoF-Template Method Pattern. Der Algorithmus (Daten laden, transformieren, formatieren) bleibt fix, aber die einzelnen Schritte sind austauschbar."
Related Anchors:
-
GoF Design Patterns (Umbrella)