学习帖,欢迎纠正,不胜感激;
建造者模式:
建造者模式最好的例子就是车辆组装;
public class Car{
public Car tire = null;
public Car engine = null;
public void setTire(String name){
tire = name;
}
public void setEngine(String name){
engine = name;
}
}
public interface Builder{
public void builderTire(){};
public void builderEngine(){};
public void builder(){};
}
public class Bmw implements Builder{
public void builderTire(){
System.out.println("BMWtire");
}
public void builderEngine(){
System.out.println("BMWEngine");
}
public void builder(){
System.out.println("BMWSUCC");
}
}
public class Deritor{
private Builder Ibuilder = null;
private void Deritor(Builder Ibuilder){
this.Ibuilder = Ibuilder;
}
public void con(){
Ibuilder.builderTire();
Ibuilder.builderEngine();
}
}