1 package com.tn.pattern; 2 3 public class Client { 4 public static void main(String[] args) { 5 AbstractClass c1=new ConcreteClass1(); 6 c1.templateMethod(); 7 8 AbstractClass c2=new ConcreteClass2(); 9 c2.templateMethod(); 10 } 11 } 12 13 abstract class AbstractClass{ 14 abstract protected void primitiveMethod1(); 15 abstract protected void primitiveMethod2(); 16 17 protected void templateMethod(){ 18 System.out.println("templateMethod() start..."); 19 primitiveMethod1(); 20 primitiveMethod2(); 21 System.out.println("templateMethod() end."); 22 } 23 } 24 25 class ConcreteClass1 extends AbstractClass{ 26 @Override 27 public void primitiveMethod1() { 28 System.out.println("ConcreteClass1's primitiveMethod1()..."); 29 } 30 @Override 31 public void primitiveMethod2() { 32 System.out.println("ConcreteClass1's primitiveMethod2()..."); 33 } 34 } 35 36 class ConcreteClass2 extends AbstractClass{ 37 @Override 38 public void primitiveMethod1() { 39 System.out.println("ConcreteClass2's primitiveMethod1()..."); 40 } 41 @Override 42 public void primitiveMethod2() { 43 System.out.println("ConcreteClass2's primitiveMethod2()..."); 44 } 45 }