Please enable JavaScript.
Coggle requires JavaScript to display documents.
Template (Consequences (Types of Methods Called: (Concrete Abstract Class…
Template
Consequences
Fundamental technique for code reuse. Used in class libraries since behavior common to classes can be factored out
-
-
Implementation
Use access modifiers for appropriate methods. For primitive methods use "protected", for the template method use "final" so it cannot be overriden
-
-
-
Related Patterns
-
Strategy: Template methods use inheritance to vary part of an algorithm. Strategies use delegation to vary the entire algorithm.
Intent
Template Method allows subclasses to redefine steps in an algorithm without changing the structure of the algorithm. An operation defines the structure of the algorithm, subclasses can redefine individual steps
-
Motivation
When you have interactions between classes that can vary depending on the domain, the template method can fix the ordering of steps in an algorithm but allow the sub class to implement the domain logic in the steps
-