Example #1
0
        static void Main(string[] args)
        {
            Director     director    = new Director();
            HouseBuilder builder     = new WoodenHouseBuilder();
            House        woodenHouse = director.Build(builder);

            Console.WriteLine(woodenHouse.ToString());

            builder = new BrickHouseBuilder();
            House brickHouse = director.Build(builder);

            Console.WriteLine(brickHouse.ToString());

            Prototype.Prototype.F();

            Command.Command.F();

            Console.ReadKey();
        }
Example #2
0
        /// <summary>
        /// Problem: If we have to initial some object that has many step or complex to initialize.
        /// Solved: Use Builder pattern to solve the problem by create the Product, Builder and Director.
        /// The Builder will handle how to create the object.
        /// The Director will handle to manage the builder for works.
        /// And in finally we will get the product via Builder get result method (GetHouse in this case).
        /// </summary>
        public override void Demo()
        {
            Console.WriteLine($"================Builder================{Environment.NewLine}");
            // in case we want to created wooden house
            var woodenHouseBuilder = new WoodenHouseBuilder();
            var houseDirector      = new HouseDirector(woodenHouseBuilder);

            houseDirector.CreateWoodenHouse();
            var woodenHouse = woodenHouseBuilder.GetHouse();

            woodenHouse.ListAllPart();

            // in case we want to create brick house
            var brickHouseBuilder = new BrickHouseBuilder();

            houseDirector = new HouseDirector(brickHouseBuilder);
            houseDirector.CreateBrickHouse();
            var brickHouse = brickHouseBuilder.GetHouse();

            brickHouse.ListAllPart();
            Console.WriteLine($"{Environment.NewLine}================Builder================");
        }