Esempio n. 1
0
        public static void Main(string[] args)
        {
            var     director = new Director();
            Builder builder1 = new ConcreteBuilder1(), builder2 = new ConcreteBuilder2();

            director.Construct(builder1);
            director.Construct(builder2);

            builder1.GetResult().Show();
            builder2.GetResult().Show();

            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Director director = new Director();
            Builder  builder1 = new ConcreteBuilder1();
            Builder  builder2 = new ConcreteBuilder2();

            director.Construct(builder1);
            builder1.GetComputer().Add("Apple");
            builder1.GetComputer().Add("戴尔");
            builder1.GetComputer().Show();

            director.Construct(builder2);
            builder2.GetComputer().Add("华硕");
            builder2.GetComputer().Show();
            Console.ReadKey();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Director director = new Director();
            Builder  b1       = new ConcreteBuilder1();
            Builder  b2       = new ConcreteBuilder2();

            director.Construct(b1);
            var product1 = b1.GetResult();

            product1.Show();

            director.Construct(b2);
            var product2 = b2.GetResult();

            product2.Show();
        }
Esempio n. 4
0
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            // create director and builders
            Director director = new Director();

            Builder b1 = new ConcreteBuilder1();
            Builder b2 = new ConcreteBuilder2();

            // create product using builder 1
            director.Construct(b1);
            Product p1 = b1.GetResult();

            // create product using builder 1
            director.Construct(b2);
            Product p2 = b2.GetResult();
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            Director d  = new Director();
            Builder  b1 = new ConcreteBuilder1();
            Builder  b2 = new ConcreteBuilder2();

            d.Construct(b1);
            Product p1 = b1.GetProduct();

            p1.Show();

            d.Construct(b2);
            Product p2 = b2.GetProduct();

            p2.Show();

            Console.ReadKey();
        }
Esempio n. 7
0
        private static void Main(string[] args)
        {
            var     director = new Director();
            Builder b1       = new ConcreteBuilder1();
            Builder b2       = new ConcreteBuilder2();

            director.Construct(b1);
            var p1 = b1.GetResult();

            p1.Show();

            director.Construct(b2);
            var p2 = b2.GetResult();

            p2.Show();

            Console.ReadKey();
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            Director director = new Director();
            Builder  b1       = new ConcreteBuilder1();
            Builder  b2       = new ConcreteBuilder2();

            director.Construct(b1);

            // 指挥者用ConcreteBuilder1的方法来建造产品
            Product p1 = b1.GetResult();

            p1.Show();
            director.Construct(b2);

            // 指挥者用ConcreteBuilder2的方法来建造产品
            Product p2 = b2.GetResult();

            p2.Show();

            Console.Read();
        }
Esempio n. 9
0
        private static void StructuralBuilder()
        {
            // Create director and builders
            Director director = new Director();
            Builder  b1       = new ConcreteBuilder1();
            Builder  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();
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            // Create director and builders
            Director director = new Director();

            Builder b1 = new ConcreteBuilder1();
            Builder b2 = new ConcreteBuilder2();

            // Construct two products
            director.Construct(b1);
            Product p1 = b1.GetResult();

            p1.Show();

            director.Construct(b2);
            Product p2 = b2.GetResult();

            p2.Show();


            //1.练习
            VehicleBuilder builder;
            // Create shop with vehicle builders
            Shop shop = new Shop();

            // Construct and display vehicles
            builder = new ScooterBuilder();
            shop.Construct(builder);
            builder.Vehicle.Show();

            builder = new CarBuilder();
            shop.Construct(builder);
            builder.Vehicle.Show();

            builder = new MotorCycleBuilder();
            shop.Construct(builder);
            builder.Vehicle.Show();

            Console.ReadKey();
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            // 客户找到电脑城老板说要买电脑,这里要装两台电脑
            // 创建指挥者和构造者
            var             director = new Director();
            AbstractBuilder b1       = new ConcreteBuilder1();
            AbstractBuilder b2       = new ConcreteBuilder2();

            // 老板叫员工去组装第一台电脑
            director.Construct(b1);

            // 组装完,组装人员搬来组装好的电脑
            var computer1 = b1.GetComputer();

            computer1.Show();

            // 老板叫员工去组装第二台电脑
            director.Construct(b2);
            var computer2 = b2.GetComputer();

            computer2.Show();

            Console.Read();
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            Director director = new Director();

            //声明一个精细构建1的类
            ConcreteBuilder1 cb1 = new ConcreteBuilder1();

            //通过统一的构造
            director.Construct(cb1);
            //得到构造后的结果
            Product p1 = cb1.GetResult();

            //声明一个精细构建2的类
            ConcreteBuilder2 cb2 = new ConcreteBuilder2();

            //通过统一的构造
            director.Construct(cb2);
            //得到构造后的结果
            Product p2 = cb2.GetResult();

            p1.Show();
            p2.Show();
            Console.ReadKey();
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            //首先需要有一個管理者
            Director director = new Director();
            //然後要有兩條實際的生產線
            Builder builder1 = new ConcreteBuilder1();
            Builder builder2 = new ConcreteBuilder2();

            //由管理者來發出命令,讓生產線生產,實際上由生產線製造
            director.Construct(builder1);

            //製造完成後,顯示出組好的成品
            Car car1 = builder1.GetCar();

            car1.Show();

            director.Construct(builder2);
            Car car2 = builder2.GetCar();

            car2.Show();


            Console.Read();
        }