Intent
Define skeleton of an algorithm in an operation, deferring some steps to
subclasses.
Applicability
- implement invariant parts of a design
- define skeleton of an algorithm
Structure
[to do: diagram with AbstractClass, DerivedClass]
Consequences
- reuse of code
- define invariant behavior
- inverted control flow
- Hollywood principle: «Don't call us we'll call you»
Implementation
- minimize the number of primitive operations: «design by primitives»
- primitive operations declared as protected
- whenn ot called by clients using the class
- primitive operations declared as final
- disallow changes to template methods in subclasses
Uses in JHotDraw
- AbstractFigure method draw (final method) calls methods drawObserver
and drawFigure (abstract methods).
- AbstractAttributedFigure method
drawFigure (final method) calls methods drawFill, drawStroke and drawText
(abstract methods)