Gof Template Method

Template Method in modern Java: fixing an algorithm's skeleton while named steps vary, and the inheritance coupling that often makes composition preferable. Covers when final protects the sequence, controlled overriding, minimal hook surfaces, the constructor-calls-an-overridable-method trap, protected hooks becoming an API you cannot change, when the pattern is genuinely right (frameworks that instantiate your subclass, contract test base classes), and how to convert one to a class taking its steps as collaborators. Use when an abstract base class with protected hooks is proposed, when a base-class change broke subclasses, when a template has grown past a handful of hooks, or when subclasses override the template method itself. Does not cover choosing a whole algorithm (gof-strategy), creating the product a template needs (gof-factory-method), the general inheritance decision (java-composition-over-inheritance), or pipeline stages contributed independently (gof-chain-of-responsibility).

robsonkades Updated

File contents

robsonkades/agent-skills/tree/main/skills/gof-template-method commit f15ad4567d

Frequently asked questions

npx skillmds@latest add robsonkades/gof-template-method