示例#1
0
        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();
        }
示例#2
0
        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();
        }
示例#3
0
        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();
        }