示例#1
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();
        }
示例#2
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());
        }
示例#3
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());
        }
示例#4
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();
        }
示例#5
0
        static void Main(string[] args)
        {
            var builder = new ConcreteBuilder();

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

            var producedProduct = builder.GetProduct();

            Console.Write(producedProduct.ListPartsNames());

            Console.ReadLine();
        }
示例#6
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()}");
            ;
        }
示例#7
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());
        }
示例#8
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());
        }