Template Method Pattern template decides the outline of processing and shares the logic Subclass processes according to the frame determined by template </ font>
Check with the following class structure
class | Explanation |
---|---|
template.class | Describe the outline of processing |
sam1.class | Flesh the details of the process |
sam2.class | Flesh the details of the process |
user(Main.class) | Check the operation of Template Pattern |
template.class
abstract class template{
abstract String temp1();
abstract String temp2();
abstract String temp3();
final void show(){
System.out.print(temp1()+temp2()+temp3()+"\n");
}
}
sam1.class
class sam1 extends template{
String temp1(){return "<<< ";}
String temp2(){return "Template";}
String temp3(){return " >>>";}
}
sam2.class
class sam2 extends template{
String temp1(){return "[[[ ";}
String temp2(){return "Template";}
String temp3(){return " ]]]";}
}
user(Main.class)
public static void main(String[] args){
sam1 s1= new sam1();
sam2 s2= new sam2();
s1.show();
s2.show();
}}
Recommended Posts