Template method Pattern: Defines the skeleton of an algorithm in one method and delays some steps into subclasses. The template method allows subclasses to be redefined without changing the structure of the algorithm. Redefine some of the steps in the algorithm.
Caffeine drinks Super Class
Java code
/** *
Caffeine Beverage Super class
* @author Panxiuyan
* * */Public
abstract class Caffeinbeverage {
/**
* Making method */public
void Perarerecip () {
boilwater ();
Brew ();
Pourincup ();
if (Customerwantscondiments ()) {
addcondimenes ();
}/** * Brew/public
abstract void Brew ();
/**
* Add related ingredients
/public
abstract void Addcondimenes ()
/**
* Boil the water
/public
void Boilwater () {
System.out.println ("boiling water"),
/**
* Meal Pour into cup
* * * public
void Pourincup () {
System.out.println ("pouring into Cup");
}
/**
* Add related ingredients-hook procedure
* @return * * Public
Boolean customerwantscondiments () {
R Eturn true;
}
}