コード例 #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
        }
コード例 #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();
    }
コード例 #3
0
        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());
        }
コード例 #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());
        }
コード例 #5
0
        private static void BuilderExample()
        {
            var director = new Director();
            var builder  = new ConcreteBuilder();

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

            product.PrintPartsList();
        }
コード例 #6
0
        public void BuilderHasOneProduct_WithoutDirector()
        {
            // Arrange
            var builder = new ConcreteBuilder();

            // Act
            builder.BuildPartA();

            // Assert
            Assert.AreEqual(1, builder.GetProduct().Parts.Count);
        }
コード例 #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());
    }
コード例 #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());
        }
コード例 #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());
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #12
0
        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");
        }
コード例 #13
0
ファイル: BuilderTests.cs プロジェクト: npoxon/DesignPatterns
        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);
        }