예제 #1
0
        static void Main(string[] args)
        {
            // Клиентский код создаёт объект-строитель, передаёт его директору,
            // а затем инициирует  процесс построения. Конечный результат
            // извлекается из объекта-строителя.
            var director = new Director();
            var builder  = new ConcreteBuilder();

            director.Builder = builder;

            Console.WriteLine("Standard basic product:");
            director.buildMinimalViableProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            Console.WriteLine("Standard full featured product:");
            director.buildFullFeaturedProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            // Помните, что паттерн Строитель можно использовать без класса
            // Директор.
            Console.WriteLine("Custom product:");
            builder.BuildPartA();
            builder.BuildPartC();
            Console.Write(builder.GetProduct().ListParts());
        }
예제 #2
0
파일: Program.cs 프로젝트: artag/Training
        // Клиентский код создаёт объект-строитель, передаёт его директору,
        // а затем инициирует  процесс построения. Конечный результат
        // извлекается из объекта-строителя.
        static void Main(string[] args)
        {
            var builder = new ConcreteBuilder();

            var directorA = new DirectorA(builder);

            Console.WriteLine("Use DirectorA. Minimal product:");
            directorA.BuildMinimalProduct();
            var minProduct = builder.GetResult();

            minProduct.Show();

            Console.WriteLine("---");
            Console.WriteLine("Use DirectorA. Full product:");
            directorA.BuildFullProduct();
            var fullProduct = builder.GetResult();

            fullProduct.Show();

            Console.WriteLine("---");
            Console.WriteLine("Use DirectorB. Minimal product:");
            var directorB = new DirectorB();

            directorB.BuildMinimalProduct(builder);
            builder.GetResult().Show();

            // Паттерн Строитель можно использовать без класса Директор.
            Console.WriteLine("---");
            Console.WriteLine("Without Director. Custom product:");
            builder.BuildPartA();
            builder.BuildPartC();
            builder.GetResult().Show();
        }
예제 #3
0
        static void Main(string[] args)
        {
            // The client code creates a builder object, passes it to the
            // director and then initiates the construction process. The end
            // result is retrieved from the builder object.
            var director = new Director();
            var builder  = new ConcreteBuilder();

            director.Builder = builder;

            Console.WriteLine("Standard basic product:");
            director.BuildMinimalViableProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            Console.WriteLine("Standard full featured product:");
            director.BuildFullFeaturedProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            // Remember, the Builder pattern can be used without a Director
            // class.
            Console.WriteLine("Custom product:");
            builder.BuildPartA();
            builder.BuildPartC();
            Console.Write(builder.GetProduct().ListParts());
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Fluent Builder design pattern example");
            Console.WriteLine("Builder is a creational design pattern, which allows constructing complex objects step by step.");
            Console.WriteLine();

            // the client code creates a builder object, passes it to the director and then initiates the construction process.
            // the end result is retrieved from the builder object.
            var director = new Director();
            var builder  = new ConcreteBuilder();

            director.Builder = builder;

            Console.WriteLine("Standard basic product:");
            director.BuildMinimalViableProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            Console.WriteLine("Standard full featured product:");
            director.BuildFullFeaturedProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            // remember, the builder pattern can be used without a director class.
            Console.WriteLine("Custom product:");
            builder
            .BuildPartA()
            .BuildPartC();
            Console.Write(builder.GetProduct().ListParts());
        }
예제 #5
0
        void Main()
        {
            Builder  builder  = new ConcreteBuilder();
            Director director = new Director(builder);

            director.Construct();
            Product product = builder.GetResult();
        }
예제 #6
0
        public static void Main(string[] args)
        {
            var builder  = new ConcreteBuilder();
            var director = new Director(builder);
            var product  = director.Build();

            Console.WriteLine(product);
        }
예제 #7
0
        public static void Main()
        {
            Builder builder = new ConcreteBuilder();
            Director director = new Director(builder);
            director.Construct();

            Product product = builder.GetResult();
            product.Show();
        }
예제 #8
0
        static void Main(string[] args)
        {
            Builder builder = new ConcreteBuilder();
            Foreman foreman = new Foreman(builder);

            foreman.Construct();

            House house = builder.GetResult();

            Console.ReadKey();
        }
예제 #9
0
        static void Main(string[] args)
        {
            Builder  builder  = new ConcreteBuilder();
            Director director = new Director(builder);

            director.Construct();

            Product product = builder.GetResult();

            product.Show();
        }
예제 #10
0
        static void Main()
        {
            var builder  = new ConcreteBuilder();
            var director = new Director(builder);

            director.Construct();

            var product = builder.GetResult();

            product.Show();
        }
예제 #11
0
        public static void Main()
        {
            Builder  builder  = new ConcreteBuilder();
            Director director = new Director(builder);

            director.Construct();
            Product product = builder.GetResult();

            product.Show();

            Console.ReadLine();
        }
예제 #12
0
        static void Main(string[] args)
        {
            Director director = new Director();

            BuilderAbstraction builder1 = new ConcreteBuilder();

            director.Construct(builder1);

            Product product = builder1.GetResult();

            product.Show();
        }
예제 #13
0
        public static void Main()
        {
            Builder builder = new ConcreteBuilder();
            Foreman foreman = new Foreman(builder);

            foreman.Construct();

            House house = builder.GetResult();

            // Delay.
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Director director = new Director();
            IBuilder builder  = new ConcreteBuilder();

            director.Construct(builder);
            Product product = builder.GetProduct();

            Console.WriteLine($"{product.Part1} / {product.Part2} / {product.Part3}");

            Console.ReadKey();
        }
예제 #15
0
        static void Main(string[] args)
        {
            /*El código del cliente crea un objeto de construcción, se lo pasa al director y
             * luego inicia el proceso de construcción.
             * El resultado final se recupera del objeto constructor.*/
            Console.WriteLine("----------Ejercicio Conceptual----------");

            var director = new Director();
            var builder  = new ConcreteBuilder();

            director.Builder = builder;
            Console.WriteLine("Standard basic product:");
            director.buildMinimalViableProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            Console.WriteLine("Standard full featured product:");
            director.buildFullFeaturedProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            /* Recuerde, el patrón Builder se puede utilizar sin una clase de Director. */

            Console.WriteLine("Custom product:");
            builder.BuildPartA();
            builder.BuildPartC();
            Console.Write(builder.GetProduct().ListParts());

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("---------- Ejercicio de prueba ----------");
            Console.WriteLine("Creando Audi.......");
            var concesionario = new Concesionario();
            var audiBuilder   = new ConcreteBuilderAudi();

            concesionario.CocheBuilder = audiBuilder;
            concesionario.construirCoche();
            Console.WriteLine(audiBuilder.GetCoche());
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("Creando Hyundai.......");
            var hyundaiBuilder = new ConcreteBuilderHyundai();

            concesionario.CocheBuilder = hyundaiBuilder;
            concesionario.construirCoche();
            Console.WriteLine(hyundaiBuilder.GetCoche());
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("Sin usar director y usando parametros....");
            audiBuilder.construirMotor(5000, 300);
            audiBuilder.DarNombre("Audi Q7");
            audiBuilder.construirCarroceria("4x4", 7);
            Console.WriteLine(audiBuilder.GetCoche());


            Console.ReadKey();
        }
예제 #16
0
파일: Program.cs 프로젝트: rolitpi/Patterns
        static void Main(string[] args)
        {
            var builder = new ConcreteBuilder();

            builder.BuildPartB();
            builder.BuildPartC();

            var producedProduct = builder.GetProduct();

            Console.Write(producedProduct.ListPartsNames());

            Console.ReadLine();
        }
예제 #17
0
        static void Main(string[] args)
        {
            Builder builder  = new ConcreteBuilder();         // VehicleBuilder - HeroHonda Builder
            var     director = new ConcreteDirector(builder); // Shop

            director.Construct();
            var finalProduct = director.GetProduct(); // The final vehicle

            finalProduct.ShowInfo();

            director = new ConcreteDirector(new ConcreteBuilder2());
            director.Construct();
            director.GetProduct().ShowInfo();
        }
예제 #18
0
        static void Main(string[] args)
        {
            Builder.Abstract.Builder builder = new ConcreteBuilder();
            Director director = new Director(builder);

            director.Construct();
            Product product = builder.GetResult();

            foreach (var part in product.parts)
            {
                Console.WriteLine(part);
            }

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

            woodBuilder.BuildFloor();
            woodBuilder.BuildWalls();
            woodBuilder.BuildRoof();
            woodBuilder.GetResult();

            var concreteBuilder = new ConcreteBuilder();

            concreteBuilder.BuildFloor();
            concreteBuilder.BuildWalls();
            concreteBuilder.BuildRoof();
            concreteBuilder.GetResult();
        }
예제 #20
0
        static void Main(string[] args)
        {
            //house building
            Builder.Builder b = new ConcreteBuilder();
            Foreman         f = new Foreman(b);

            f.Construct();
            House h = b.GetResult();

            //bottle building
            BottleBuilder.BottleBuilder bb = new PepsiBottleBuilder();
            Director d = new Director(bb);

            d.Construct();
            Bottle bottle = bb.GetBottle();
        }
예제 #21
0
        static void Main(string[] args)
        {
            var builder  = new ConcreteBuilder();
            var director = new Director();

            director.Builder = builder;

            director.BuildMinimalViableProduct();
            Console.WriteLine($"{builder.GetProduct().ListParts()}");

            director.BuildFullFeaturedProduct();
            Console.WriteLine($"{builder.GetProduct().ListParts()}");

            builder.BuildPartA();
            builder.BuildPartC();
            Console.WriteLine($"{builder.GetProduct().ListParts()}");
            ;
        }
예제 #22
0
        static void Main(string[] args)
        {
            var director = new Director();
            var builder  = new ConcreteBuilder();

            director.Builder = builder;
            Console.WriteLine("Standard basic product:");
            director.buildMinimalViableProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            Console.WriteLine("Standard full featured product:");
            director.buildFullFeaturedProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            Console.WriteLine("Custom product:");
            builder.BuildPartA();
            builder.BuildPartC();
            Console.Write(builder.GetProduct().ListParts());
        }
        static void Main(string[] args)
        {
            // The client code creates a builder object, passes it to the
            // director and then initiates the construction process. The end
            // result is retrieved from the builder object.
            var director = new Director();
            var builder  = new ConcreteBuilder();

            director.Builder = builder;

            Console.WriteLine("Standard basic product (variation #1):");
            director.BuildMinimalViableProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            Console.WriteLine("Standard full featured product (variation #2):");
            director.BuildFullFeaturedProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            Console.Read();
        }
예제 #24
0
        static void Main(string[] args)
        {
            var director = new Director();
            var builder  = new ConcreteBuilder();

            director.Builder = builder;

            Console.WriteLine("Standard basic product:");
            director.buildMinimalViableProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            Console.WriteLine("Standard full featured product:");
            director.buildFullFeaturedProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            // Помните, что паттерн Строитель можно использовать без класса
            // Директор.
            Console.WriteLine("Custom product:");
            builder.BuildPartA();
            builder.BuildPartC();
            Console.Write(builder.GetProduct().ListParts());
        }
예제 #25
0
        /// <summary>
        /// 建造者模式:主要用于创建一个复杂的对象,这些对象的内部构建顺序一般是稳定的,
        /// 但是这些对象内部结构通常面临着复杂的变化(也就是说抽象建造者类里的抽闲方法的实现是复杂变化的)
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //先创建一个指挥者
            Director director = new Director();
            //在创建一个具体的建造者
            ConcreteBuilder     concreteBuilder        = new ConcreteBuilder();
            ConcreteBuilderIpad concreteBuilderiapIpad = new ConcreteBuilderIpad();

            //指挥者开始指挥来
            //指挥concreteBuilder开始构建产品
            director.Construct(concreteBuilder);
            //指挥concreteBuilder得到产品
            Product p1 = concreteBuilder.GetResult();

            p1.Show();

            //第二次指挥
            director.Construct(concreteBuilderiapIpad);
            Product p2 = concreteBuilderiapIpad.GetResult();

            p2.Show();
            Console.ReadKey();
        }
예제 #26
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            var builder  = new ConcreteBuilder();
            var director = new HouseOrganizer(builder);

            //director.Builder = builder;

            Console.WriteLine("Standard basic product:");
            director.buildMinimalViableProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            Console.WriteLine("Standard full featured product:");
            director.buildFullFeaturedProduct();
            Console.WriteLine(builder.GetProduct().ListParts());

            // Remember, the Builder pattern can be used without a Director
            // class.
            Console.WriteLine("Custom product:");
            builder.BuildFoundations();
            builder.BuildMainHouse();
            Console.Write(builder.GetProduct().ListParts());
        }
예제 #27
0
        //The builder separates the constrution of an complex object.
        static void Main(string[] args)
        {
            //Create two diffrent builders.
            ConcreteBuilder        concreteBuilder        = new ConcreteBuilder();
            AnotherConcreteBuilder anotherConcreteBuilder = new AnotherConcreteBuilder();

            //Create the director and set inital builder and build.
            Director director = new Director(concreteBuilder);

            director.MakeObject();

            //Create the director and set inital builder and build.
            Director director2 = new Director(anotherConcreteBuilder);

            director2.MakeObject();

            //Get objects from builder.
            Class1 createdObject1 = director.GetObject();
            Class1 createdObject2 = director2.GetObject();

            //Output resulting objects.
            Console.WriteLine(createdObject1.Class1String);
            Console.WriteLine(createdObject2.Class1String);
        }
예제 #28
0
 static void Main(string[] args)
 {
     var builder  = new ConcreteBuilder();
     var director = new Director(builder);
     var product  = director.BuildProduct();
 }