设计模式---模板模式
/*
* 组装车
*/
public abstract class MakeCar {
//组装车头
public abstract void makeHead();
//组装车身
public abstract void makeBody();
//组装车尾
public abstract void makeTail();
public void make() {
this.makeHead();
this.makeBody();
this.makeTail();
}
}
public class MakeBus extends MakeCar {
public void makeBody() {
System.out.println("bus:组装车身");
}
public void makeHead() {
System.out.println("bus:组装车头");
}
public void makeTail() {
System.out.println("bus:组装车尾");
}
}
public class MakeJeep extends MakeCar {
public void makeBody() {
System.out.println("jeep:组装车身");
}
public void makeHead() {
System.out.println("jeep:组装车头");
}
public void makeTail() {
System.out.println("jeep:组装车尾");
}
}
public class MakeKa extends MakeCar {
public void makeBody() {
System.out.println("ka:组装车身");
}
public void makeHead() {
System.out.println("ka:组装车头");
}
public void makeTail() {
System.out.println("ka:组装车尾");
}
}
public class MainClass {
public static void main(String[] args) {
MakeCar bus = new MakeBus();
// bus.makeHead();
// bus.makeBody();
// bus.makeTail();
bus.make();
System.out.println("-------------------");
MakeCar jeep = new MakeJeep();
// jeep.makeHead();
// jeep.makeBody();
// jeep.makeTail();
jeep.make();
System.out.println("-------------------");
MakeCar ka = new MakeKa();
ka.make();
}
}