public abstract class Abstractclass {
public abstract void PrimitiveOperation1();
public abstract void PrimitiveOperation2();
public void TemplateMethod() {
PrimitiveOperation1();
PrimitiveOperation2();
System.out.println("");
}
}
public class ConcreteClassA extends Abstractclass {
@Override
public void PrimitiveOperation1() {
System.out.println("具体类A方法1的实现");
}
@Override
public void PrimitiveOperation2() {
System.out.println("具体类A方法2的实现");
}
}
public class ConcreteClassB extends Abstractclass {
@Override
public void PrimitiveOperation1() {
System.out.println("具体类B方法1的实现");
}
@Override
public void PrimitiveOperation2() {
System.out.println("具体类B方法2的实现");
}
}
public class TestUtil {
public static void main(String[] args) throws CloneNotSupportedException {
Abstractclass abstractclass = new ConcreteClassA();
abstractclass.TemplateMethod();
Abstractclass abstractclass1 = new ConcreteClassB();
abstractclass1.TemplateMethod();
}
}