static void Main(string[] args) { Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); Director director = new Director(); director.Construct(b1); Product p1 = b1.GetResult(); p1.Show(); director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); Console.ReadLine(); }
static void RunBuilder() { // 建造者关系一个产品的构造 // 产品构造通常很复杂或者需要分部构造 Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); // Construct two products director.Construct(b1); BuilderProduct p1 = b1.GetResult(); p1.Show(); director.Construct(b2); BuilderProduct p2 = b2.GetResult(); p2.Show(); }
private static void GetBuilderPattern() { // Create director and builders Director director = new Director(); IBuilder b1 = new ConcreteBuilder1(); IBuilder b2 = new ConcreteBuilder2(); // Construct two products director.Construct(b1); Product p1 = b1.GetResult(); p1.Show(); director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); // Wait for user Console.ReadKey(); }
// 建造者模式 将一个复杂类的表示与其构造相分离,使得相同的构建过程能够得出不同的表示。 static void Builder() { // 客户找到电脑城老板说要买电脑,这里要装两台电脑 // 创建指挥者和构造者 Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); // 老板叫员工去组装第一台电脑 director.Construct(b1); // 组装完,组装人员搬来组装好的电脑 Computer computer1 = b1.GetComputer(); computer1.Show(); // 老板叫员工去组装第二台电脑 director.Construct(b2); Computer computer2 = b2.GetComputer(); computer2.Show(); Console.Read(); }
static void Main(string[] args) { // 客户找到电脑城老板说要买电脑,这里要装两台电脑 // 创建指挥者和构造者 Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); // 老板叫员工去组装第一台电脑 director.Construct(b1); // 组装完,组装人员搬来组装好的电脑 Computer computer1 = b1.GetComputer(); computer1.Show(); // 老板叫员工去组装第二台电脑 director.Construct(b2); Computer computer2 = b2.GetComputer(); computer2.Show(); Console.Read(); }