Java Reference
In-Depth Information
Pattern
Template method
Context
Abstract methods and method redefinition.
Problem
Two or more components have similar data structures and
functionalities. The implementation of some methods may
differ, but their external behaviour is similar.
Forces or tradeoffs
When the behaviour of a method is complex and its
implementations in a variety of components are slightly
different, loading of the entire method may be too heavy.
Solution
Define the skeleton of the common method and separate
common operation steps from the variable ones. Substitute
the code implementing the variable steps with invocations
to abstract methods. Implement the abstract methods in
subclasses.
Examples
AbstractClass
// . . . code . . .
step()
// . . . code . . .
complexMethod()
step()
ConcreteClass1
ConcreteClass2
step()
step()
Force resolution
The pattern supports the reuse of the structure of a
complex method and requires only the redefinition
(customization) of the variable parts.
Design rationale
The Template method design pattern defines hook
operations that permit behaviour extension of a complex
method only at specific points.
10.9
References
Gamma, E., Helm, R., Johnson, R. and Vlissides, J. (1995) Design Patterns: Elements
of Reusable Object-Oriented Software , Addison-Wesley.
Nehmzow, U. (2000) Mobile Robotics: A Practical Introduction , Springer-Verlag.
 
Search WWH ::




Custom Search