public Pizza CreatePizza(string type) { Pizza pizza = null; switch (type) { case "cheese": pizza = new CheesePizza(); break; case "pepperoni": pizza = new PepperoniPizza(); break; case "clam": pizza = new ClamPizza(); break; case "veggie": pizza = new VeggiePizza(); break; default: pizza = new CrustPizza(); break; } return(pizza); }
internal override Pizza CreatePizza(string item) { Pizza pizza = null; IPizzaIngredientFactory ingredientFactory = new NYPizzaIngredientFactory(); if (item.Equals("cheese")) { pizza = new CheesePizza(ingredientFactory); pizza.Name = "California Style Cheese Pizza"; } else if (item.Equals("veggie")) { pizza = new VeggiePizza(ingredientFactory); pizza.Name = "California Style Veggie Pizza"; } else if (item.Equals("clam")) { pizza = new ClamPizza(ingredientFactory); pizza.Name = "California Style Clam Pizza"; } else if (item.Equals("pepperoni")) { pizza = new PepperoniPizza(ingredientFactory); pizza.Name = "California Style Pepperoni Pizza"; } return(pizza); }
public void OderPizza(string type) { Pizza pizza; switch (type) { case "cheese": pizza = new CheesePizza(); break; case "greek": pizza = new GreakPizza(); break; case "pepperoni": pizza = new PepperoniPizza(); break; default: Console.WriteLine("we do not have " + type); return; } pizza.Prepare(); pizza.Bake(); pizza.Cut(); pizza.Box(); }
// look at the two pizza classes and spot the similarities. Try to encapsulate them // in a way that preserves the steps of the pizza making algorithm public static void Main() { Console.WriteLine("Making pepperoni pizza\n"); PepperoniPizza pepperoniPizza = new PepperoniPizza(); pepperoniPizza.Prepare(); Console.WriteLine("\nMaking vegetarian pizza\n"); VegetarianPizza vegetarianPizza = new VegetarianPizza(); vegetarianPizza.Prepare(); Console.WriteLine("\nPress any key to end..."); Console.ReadKey(); }
public Pizza OrderPizza(string type) { Pizza pizza; // Problem is that this needs to be modified every time a new pizza class is created. // Modified here and anywhere else that instantiates a pizza class. switch (type) { case "cheese": pizza = new CheesePizza(); break; case "pepperoni": pizza = new PepperoniPizza(); break; case "clam": pizza = new ClamPizza(); break; case "veggie": pizza = new VeggiePizza(); break; default: pizza = new CrustPizza(); break; } pizza.Prepare(); pizza.Bake(); pizza.Cut(); pizza.Box(); return(pizza); }