模板方法模式
public abstract class AbstractClass {
protected abstract void doSomething();
protected abstract void doOthers();
public void templateMethod(){
this.doSomething();
this.doOthers();
}
}
public class ConcreteClass1 extends AbstractClass{
protected void doSomething() {
// TODO Auto-generated method stub
}
protected void doOthers() {
// TODO Auto-generated method stub
}
}
public class ConcreteClass2 extends AbstractClass {
protected void doSomething() {
// TODO Auto-generated method stub
}
protected void doOthers() {
// TODO Auto-generated method stub
}
}
public class Client {
public static void main(String[] args){
AbstractClass class1 = new ConcreteClass1();
AbstractClass class2 = new ConcreteClass2();
class1.templateMethod();
class2.templateMethod();
}
}