Exemplo n.º 1
0
        static void Main(string[] args)
        {
            #region --Prototipe

            //IFigure figure = new Rectangle(10, 50);
            //IFigure clonedRect = figure.Clone();
            //figure.ShowInfo();
            //clonedRect.ShowInfo();

            //figure = new Circle(50);
            //IFigure clonedCirc = figure.Clone();
            //figure.ShowInfo();
            //clonedCirc.ShowInfo();

            //Console.Read();
            #endregion

            #region --Builder


            var builder  = new ConcreteBuilder();
            var director = new Director(builder);
            director.FullConstruct();
            Console.WriteLine(builder.GetProduct().ListParts());
            builder.Reset();
            director.MinConstruct();
            Console.WriteLine(builder.GetProduct().ListParts());
            Console.Read();

            #endregion
        }
Exemplo n.º 2
0
    public static void Main()
    {
        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());

        var breadBuilder = new BreadBuilder();

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

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

        Console.WriteLine("Custom product:");
        builder.BuildPartA();
        builder.BuildPartC();
        Console.Write(builder.GetProduct().ListParts());
        Console.ReadKey();
    }
        public void Main()
        {
            // 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());
        }
Exemplo n.º 4
0
        // Builder -> separate constructor of a complex object from its representation
        public void ClientBuilder()
        {
            Builder  builder  = new ConcreteBuilder();
            Director director = new Director(builder);

            director.Construct();
            Creational.Builder.Product product = builder.GetProduct();
            Console.WriteLine(product.ToString());
        }
Exemplo n.º 5
0
        private static void BuilderExample()
        {
            var director = new Director();
            var builder  = new ConcreteBuilder();

            director.Build(builder);
            var product = builder.GetProduct();

            product.PrintPartsList();
        }
        public void BuilderHasOneProduct_WithoutDirector()
        {
            // Arrange
            var builder = new ConcreteBuilder();

            // Act
            builder.BuildPartA();

            // Assert
            Assert.AreEqual(1, builder.GetProduct().Parts.Count);
        }
Exemplo n.º 7
0
    static void Main(string[] args)
    {
        Director        director = new Director();
        ConcreteBuilder 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());
    }
Exemplo n.º 8
0
        private static void ExecutarBuilder()
        {
            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());
        }
Exemplo n.º 9
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());

            //Remember, the builder pattern can be used without a director class
            Console.WriteLine("Custom product:");
            builder.BuildPartA();
            builder.BuildPartC();
            Console.WriteLine(builder.GetProduct().ListParts());
        }
Exemplo n.º 10
0
        public void BulderHasMinimalViableProducts_WithDirector()
        {
            // Arrange
            var director = new Director();
            var builder  = new ConcreteBuilder();

            director.Builder = builder;

            // Act
            director.buildMinimalViableProduct();

            // Assert
            Assert.AreEqual(1, builder.GetProduct().Parts.Count);
        }
Exemplo n.º 11
0
        public void BulderHasAllProducts_WithDirector()
        {
            // Arrange
            var director = new Director();
            var builder  = new ConcreteBuilder();

            director.Builder = builder;

            // Act
            director.buildFullFeaturedProduct();

            // Assert
            Assert.AreEqual(3, builder.GetProduct().Parts.Count);
        }
        public void TestBuilder()
        {
            IBuilder builder = new ConcreteBuilder();

            builder.BuildPartOne("Part 1");
            builder.BuildPartTwo("Part 2");
            builder.BuildPartThree("Part 3");

            var product = builder.GetProduct();

            Assert.AreEqual(product.PartOne, "Part 1");
            Assert.AreEqual(product.PartTwo, "Part 2");
            Assert.AreEqual(product.PartThree, "Part 3");
        }
Exemplo n.º 13
0
        public void BuilderTest()
        {
            // 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;

            // Create a standard basic product
            director.BuildMinimalViableProduct();
            builder.GetProduct().ListParts().Should().ContainInOrder(Text.PartA);

            // Create a standard full featured product
            director.BuildFullFeaturedProduct();
            builder.GetProduct().ListParts().Should().ContainInOrder(Text.PartA, Text.PartB, Text.PartC);

            // Remember, the Builder pattern can be used without a Director
            // class.
            builder.BuildPartA();
            builder.BuildPartC();
            builder.GetProduct().ListParts().Should().ContainInOrder(Text.PartA, Text.PartC);
        }