建造模式将一个产品的内部表象与产品的生成过程分割开来,从而使一个建造过程可以生成具有不同内部表象的产品对象。
public class Director {
public void construct(){
Builder builder1 = new ConcreteBuilder1();
builder1.buildPart1();
builder1.buildPart2();
builder1.retrieveProduct();
}
}
public interface Builder { public abstract Object buildPart1(); public abstract Object buildPart2(); public abstract Product retrieveProduct(); }
public class ConcreteBuilder1 implements Builder {
private Object part1,part2;
@Override
public Object buildPart1() {
part1 = new Object();
return part1;
}
@Override
public Object buildPart2() {
part2 = new Object();
return part2;
}
@Override
public Product retrieveProduct() {
Product1 p = new Product1();
return p;
}
}
public interface Product { public abstract void function(); }
public class Product1 implements Product { @Override public void function() { } }
原文:http://www.cnblogs.com/lnlvinso/p/3807115.html