static void Main(string[] args)
        {
            // 1. Create an instance for Builder and initialize with Concrete builder - ChesePizzaBuilder.
            PizzaBuilder chesePizzaBuilder = new ChesePizzaBuilder();

            // 2. Create an instance for Director.
            Cook cook = new Cook();

            // 3. By using Director instance, call the concrete object methods.
            cook.SetPizzaBuilder(chesePizzaBuilder);
            cook.ConstructPizza();

            // 4. Create and get the product, by using the Director.
            Pizza chesePizzaProduct = cook.GetPizza();

            // 5. Deliver the product.
            Console.WriteLine("Chese Pizza prepared by using " + chesePizzaProduct.Topping + " and " + chesePizzaProduct.Sauce);

            // 1. Create an instance for Builder and initialize with Concrete builder - SpicyPizzaBuilder.
            PizzaBuilder spicyPizzaBuilder = new SpicyPizzaBuilder();

            // 2. Use same Director instance.
            // 3. And pass the new concrete Builder instance.
            cook.SetPizzaBuilder(spicyPizzaBuilder);
            cook.ConstructPizza();

            // 4. Create and get the product, by using the Director.
            Pizza spicyPizzaProduct = cook.GetPizza();

            // 5. Deliver the product.
            Console.WriteLine("Spicy Pizza prepared by using " + spicyPizzaProduct.Topping + " and " + spicyPizzaProduct.Sauce);

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // 1. Create an instance for Builder and initialize with Concrete builder - ChesePizzaBuilder.
            PizzaBuilder chesePizzaBuilder = new ChesePizzaBuilder();

            // 2. Create an instance for Director.
            Cook cook = new Cook();
                        
            // 3. By using Director instance, call the concrete object methods.
            cook.SetPizzaBuilder(chesePizzaBuilder);
            cook.ConstructPizza();
            
            // 4. Create and get the product, by using the Director.
            Pizza chesePizzaProduct = cook.GetPizza();

            // 5. Deliver the product.
            Console.WriteLine("Chese Pizza prepared by using " + chesePizzaProduct.Topping + " and " + chesePizzaProduct.Sauce);

            // 1. Create an instance for Builder and initialize with Concrete builder - SpicyPizzaBuilder.
            PizzaBuilder spicyPizzaBuilder = new SpicyPizzaBuilder();

            // 2. Use same Director instance.
            // 3. And pass the new concrete Builder instance.
            cook.SetPizzaBuilder(spicyPizzaBuilder);
            cook.ConstructPizza();

            // 4. Create and get the product, by using the Director.
            Pizza spicyPizzaProduct = cook.GetPizza();

            // 5. Deliver the product.
            Console.WriteLine("Spicy Pizza prepared by using " + spicyPizzaProduct.Topping + " and " + spicyPizzaProduct.Sauce);

            Console.ReadLine();
        }