Template Method Pattern

Template Method Pattern template decides the outline of processing and shares the logic Subclass processes according to the frame determined by template </ font>

Design Pattarm MENU

Template Method Pattern Example

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
  • User Includes the meaning that other developers use this 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

Template Method pattern
Template Method Pattern
Design pattern ~ Template Method ~
Ruby design pattern template method pattern memo
Factory Method Pattern
Factory Method pattern
[Design pattern] Common logic with Template Method
Design pattern ~ Factory Method ~
Java8 Lambda expression & Stream design pattern reconsideration --Template Method pattern -
Java beginner design pattern (Factory Method pattern)
Prototype pattern
Memento Pattern
Mediator pattern
Composite pattern
Java method
to_i method
Observer Pattern
java (method)
getRequestDispatcher () method
merge method
Builder Pattern
Strategy pattern
Iterator Pattern
Visitor pattern
Adapter Pattern
Map method
Proxy Pattern
Strategy Pattern
Composite Pattern
Abstract method
initialize method
Singleton Pattern
List method
Singleton pattern
Prototype Pattern
puts method
Java method
Class method
Facade Pattern
save! method
getParameter method
[Java] method
Mod template
Decorator pattern
Flyweight Pattern
Decorator Pattern
Mediator Pattern
private method
Facade pattern
Visitor Pattern
rails method
Bridge pattern
[Java] method