operation1();
operation2();
operation3();
- AbstractTemplate.java
- ConcreteTemplate.java
- TemplateTester.java
- AbstractTemplateWithHook.java
- ConcreteTemplateWithHook.java
- TemplateTesterWithHook.java
final void templateMethod() {
operation1();
operation2();
if (hook())
operation3();
}
|
The Template Method in the Java API
The template method is practiced widely in the
Java API. The java.util.Arrays class provides a sort()
method that internally uses the template method to sort an array of objects.
Java applets also practice the template method with extensive use of hooks.
The following program illustrates how the JFrame classes uses the template method pattern as well.
>> MyFrame.java
|
- Omelette.java
- ScrambledEggs.java
- SunnySide.java
- EatBreakfast.java