设计模式-模板模式
抽象类模板
public class ConcreteA extends A {
@Override
public void f1() {
System.out.println("ca");
}
@Override
public void f2() {
System.out.println("ca");
}
}
实现类
public class ConcreteA extends A {
@Override
public void f1() {
System.out.println("ca");
}
@Override
public void f2() {
System.out.println("ca");
}
}
public class ConcreteB extends A {
@Override
public void f1() {
System.out.println("cb");
}
@Override
public void f2() {
System.out.println("cb");
}
}
测试一下
public static void main(String[] args) {
A a = new ConcreteA();
a.temp();
A a1 = new ConcreteB();
a1.temp();
}
结果