Beispiel #1
0
        public Pizza OrderPizza(string type)
        {
            Pizza pizza;

            //  - - - - - - THIS IS WHAT VARIES.
            switch (type)
            {
            case "cheese":
                pizza = new CheesePizza();
                break;

            case "pepperoni":
                pizza = new PepperoniPizza();
                break;

            // Note: This code is not close for modification.
            // If the pizza offering changes, we have to modify this code.
            default:
                Console.WriteLine("Invalid pizza type!");
                return(null);
            }
            //  - - - - - - - - - - - - - - - - - -

            // THIS IS WHAT WE EXPECT TO STAY THE SAME.
            pizza.Prepare();
            pizza.Bake();
            pizza.Cut();
            pizza.Box();

            return(pizza);
        }
Beispiel #2
0
        public override ProductPizza CreatePizza(string item)
        {
            ProductPizza            pizza             = null;
            IPizzaIngredientFactory ingredientFactory = new NYPizzaIngredientFactory();

            if (item.Equals("Cheese"))
            {
                pizza      = new CheesePizza(ingredientFactory);
                pizza.Name = "New York Style Cheese Pizza";
                Console.WriteLine("Iftekhar odered a " + pizza.Name);
                pizza.Prepare();
            }
            else if (item.Equals("Veggie"))
            {
                pizza      = new VeggiePizza(ingredientFactory);
                pizza.Name = "New York Style Veggie Pizza";
                pizza.Prepare();
            }
            else if (item.Equals("Clam"))
            {
                pizza      = new ClamPizza(ingredientFactory);
                pizza.Name = "New York Style Clam Pizza";
                pizza.Prepare();
            }
            else if (item.Equals("Pepperoni"))
            {
                pizza      = new PepperoniPizza(ingredientFactory);
                pizza.Name = "New York Style Pepperoni Pizza";
                pizza.Prepare();
            }

            return(pizza);
        }
        public void PepperoniPizzaPrepareTest()
        {
            PizzaAbstract Pizza = new PepperoniPizza();
            string        s     = Pizza.Prepare();

            Assert.AreEqual("Pepperoni Pizza", s);
        }