public static void Run()
        {
            Console.WriteLine("This structural code demonstrates the Builder pattern in which complex objects are created in a step-by-step fashion. The construction process can create different object representations and provides a high level of control over the assembly of the objects.");
            Director director = new Director();

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

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

            p1.Show();

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

            p2.Show();

            /*
             * Product Parts -------
             * PartA
             * PartB
             *
             * Product Parts -------
             * PartX
             * PartY
             */
        }
예제 #2
0
        static void Main(string[] args)
        {
            Director director = new Director();



            Builder b1 = new ConcreteBuilder1();

            Builder b2 = new ConcreteBuilder2();



            // Constructor dos productos

            director.Construct(b1);

            Product p1 = b1.GetResult();

            p1.Show();



            director.Construct(b2);

            Product p2 = b2.GetResult();

            p2.Show();



            // Esperando a usar

            Console.ReadKey();
        }
예제 #3
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>

        public static void Main()
        {
            // 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();
        }
예제 #4
0
        static void Main()
        {
            Builder b1 = new ConcreteBuilder1();

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

            p1.Show();
        }
예제 #5
0
        static void Main()
        {
            Builder b1 = new ConcreteBuilder1();
            Director director = new Director();

            director.Construct(b1);
            var p1 = b1.GetResult();
            p1.Show();
        }
예제 #6
0
        static void Main(string[] args)
        {
            Director director = new Director();
            Builder  b1       = new ConcreteBuilder1();

            director.Construct(b1);
            Product pr = b1.GetResult();

            pr.show();
            Console.ReadKey();
        }
예제 #7
0
        static void Main(string[] args)
        {
            //builder에 메소드를 추가하여 Product의 속성의 값을 조작함으로써 복잡한 객체 생성을 간단하게 할 수 있습니다.
            //또한 builder 패턴은 이와 다른 여러 구현방법이 존재합니다.
            var builder1 = new ConcreteBuilder1();
            var builder2 = new ConcreteBuilder2();
            var direct1  = new Director(builder1);
            var direct2  = new Director(builder2);

            Console.WriteLine($"direct1 Product.str: {direct1.Construct().str}");
            Console.WriteLine($"direct2 Product.str: {direct2.Construct().str}");
        }
예제 #8
0
        static void Main(string[] args)
        {
            Builder  builder  = new ConcreteBuilder1();
            Director director = new Director();

            director.Construct(builder);
            Console.WriteLine(builder.GetResult().PartA);
            Console.WriteLine(builder.GetResult().PartB);

            builder = new ConcreteBuilder2();
            director.Construct(builder);
            Console.WriteLine(builder.GetResult().PartA);
            Console.WriteLine(builder.GetResult().PartB);
        }
예제 #9
0
        static void Main(string[] args)
        {
            Director director = new Director();

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

            director.Construct(b1);
            Console.WriteLine(b1.GetProduct());

            director.Construct(b2);
            Console.WriteLine(b2.GetProduct());

            Console.ReadKey();
        }
예제 #10
0
        static void Main(string[] args)
        {
            Director director = new Director();
            Builder  b1       = new ConcreteBuilder1();
            Builder  b2       = new ConcreteBuilder2();

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

            p1.Show();

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

            p2.Show();
        }
예제 #11
0
        static void Main(string[] args)
        {
            Director         d   = new Director();
            ConcreteBuilder1 cb1 = new ConcreteBuilder1();
            ConcreteBuilder2 cb2 = new ConcreteBuilder2();

            d.Construct(cb1);
            Product p1 = cb1.getResult();

            p1.show();

            d.Construct(cb2);
            Product p2 = cb2.getResult();

            p1.show();
        }
예제 #12
0
        static void Main(string[] args)
        {
            Director director = new Director();
            Builder b1= new ConcreteBuilder1();
            Builder b2 = new ConcreteBuilder2();

            director.Construct(b1);
            Product p1 = b1.GetResult();
            p1.Show();

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

            Console.ReadKey();
        }
예제 #13
0
        public static void Main()
        {
            Director director = new Director();
            Builder  b1       = new ConcreteBuilder1();
            Builder  b2       = new ConcreteBuilder2();

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

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

            p2.Show();
            Console.ReadKey();
        }
예제 #14
0
파일: Builder.cs 프로젝트: Thifer/Patterns
        public void Run()
        {
            Director director = new Director();
            Builder  b1       = new ConcreteBuilder1();
            Builder  b2       = new ConcreteBuilder2();

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

            p1.Show();

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

            p2.Show();
        }
예제 #15
0
        static void Main(string[] args)
        {
            Director director = new Director();

            IBuilder builder1 = new ConcreteBuilder1();
            IBuilder builder2 = new ConcreteBuilder2();

            director.Construct(builder1);
            Product product1 = builder1.GetResult();
            product1.Show();

            director.Construct(builder2);
            Product product2 = builder2.GetResult();
            product2.Show();

            Console.Read();
        }
        static void Main()
        {
            Director        director = new Director();
            AbstractBuilder b1       = new ConcreteBuilder1();
            AbstractBuilder b2       = new ConcreteBuilder2();

            director.Construct(b1);
            Product p1 = b1.BuildProduct();

            p1.Show();

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

            p2.Show();

            Console.ReadKey();
        }
예제 #17
0
    public static void Main()
    {
      // 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.Read();
    }
        // Bu örnekte;
        // ConcreteBuilder => ürün nesnesini oluşturan sınıf. (Her farklı ürün için ayrı bir ConcreteBuilder vardır)
        // Builder => ConcreteBuilder sııflarının ata sınıfı.
        // Product => Ürün nesnesini tutan sınıftır.
        // Director => Ürün oluşumunu yöneten sınıf.

        public static void run()
        {
            string[] partList1 = { "a", "b", "c" };
            string[] partList2 = { "d", "e", "f" };

            Builder builder = new ConcreteBuilder1();

            Director.Construct(builder, partList1);
            Product product1 = builder.GetProduct();

            Console.WriteLine(product1.ToString());

            builder = new ConcreteBuilder2();
            Director.Construct(builder, partList2);
            Product product2 = builder.GetProduct();

            Console.WriteLine(product2.ToString());

            Console.ReadKey();
        }
예제 #19
0
        public static void Main(string[] args)
        {
            var director = new Director();

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

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

            product1.Show();

            Console.WriteLine();

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

            product2.Show();

            Console.ReadKey();
        }
예제 #20
0
        static void Main(string[] args)
        {
            #region 结构实现
            // Create director and builders
            Director director = new Director();

            Structural.Builder b1 = new ConcreteBuilder1();
            Structural.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();
            #endregion

            Console.WriteLine("******************************");

            #region 实践应用
            VehicleBuilder builder;
            Shop           shop = new Shop();

            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();
            #endregion

            Console.ReadKey();
        }
예제 #21
0
        public void Main()
        {
            Director         director = new Director();
            ConcreteBuilder1 builder1 = new ConcreteBuilder1();
            ConcreteBuilder2 builder2 = new ConcreteBuilder2();

            director.Builder = builder1;

            Debug.WriteLine("Min Product by ConcreteBuilder1: ");
            director.BuildMinimalProduct();
            Debug.WriteLine(director.Builder.GetProduct());
            Debug.WriteLine("Max Product by ConcreteBuilder1: ");
            director.BuildMaximalProduct();
            Debug.WriteLine(director.Builder.GetProduct());

            director.Builder = builder2;
            Debug.WriteLine("Min Product by ConcreteBuilder2: ");
            director.BuildMinimalProduct();
            Debug.WriteLine(director.Builder.GetProduct());
            Debug.WriteLine("Max Product by ConcreteBuilder2: ");
            director.BuildMaximalProduct();
            Debug.WriteLine(director.Builder.GetProduct());
        }
예제 #22
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();
        }