建造者模式


public class Product
{
    public void doSomething()
        {
            //独立业务处理
        }
}
public abstract class Builder
{
    //设置产品的不同部分,以获得不同的产品
    public abstract void setPart();
    //建造产品
    public abstract Product builderProducct();
}
public class ConcreteProduct:Builder
{
    private Product product = new Product();
    //设置产品零件
    public void setPart()
    {
        //产品类内逻辑处理
     }
    //组建一个产品
    public Product builderProduct()
    {
        return product;
    }
}
public class Director
{
     private Builder builder = new ConcreteProduct();
    //构建不同的产品
    public Product getAProduct()
    {
        builder.setPart();
        return builder.builderProduct();
    }
}