gof-template-method
Installation
SKILL.md
One-line summary
Define the skeleton of an algorithm in a base method, deferring some steps to subclasses — letting subclasses redefine certain steps without changing the algorithm's structure.
When to use this skill
- Two or more classes follow the same overall procedure but differ in one or two steps (Beck's "Coffee and Tea both brew" example).
- A workflow has a fixed sequence but specific stages vary by use case (e.g., a parsing pipeline where the tokenize step differs per format).
- Cross-cutting framework hooks: a base class provides lifecycle methods, subclasses override the ones they care about (Spring's
JdbcTemplate, JUnit'ssetUp/tearDown).
When NOT to use this skill
- The variation is the algorithm itself, not steps within a skeleton — that's
gof-strategy. - Only one step varies and the variation is small — a function parameter or lambda is simpler than a subclass.
- The base class becomes an inheritance choke point that prevents the subclass from doing anything outside the template — that's a sign the abstraction is too rigid.
Core content
A TemplateMethod is a (typically final or non-overridable) method on the base class that calls a sequence of steps, some implemented in the base, others abstract or "hook" methods that subclasses override.