protected override Pizza CreatePizza(string type) { Pizza pizza = null; IPizzaIngredientFactory ingredientFactory = new NewYorkIngredientFactory(); if (type.Equals("Cheese")) { pizza = new CheesePizza(ingredientFactory); pizza.SetName("New York Style Cheese"); } else if (type.Equals("Greek")) { pizza = new GreekPizza(ingredientFactory); pizza.SetName("New York Style Greek"); } else if (type.Equals("Pepperoni")) { pizza = new PepperoniPizza(ingredientFactory); pizza.SetName("New York Style Cheese Pepperoni"); } else if (type.Equals("Veggie")) { pizza = new VeggiePizza(ingredientFactory); pizza.SetName("New York Style Veggie"); } else if (type.Equals("Clam")) { pizza = new ClamPizza(ingredientFactory); pizza.SetName("New York Style Clam"); } return(pizza); }
public static Burger Create(ShopType shopType, BurgerType burgerType) { //// 製作漢堡的工廠 IBurgerFactory burgerFactory = null; if (burgerType == BurgerType.Chicken) { burgerFactory = new ChickenBurgerFactory(); } else if (burgerType == BurgerType.Pork) { burgerFactory = new PorkBurgerFactory(); } else if (burgerType == BurgerType.Fish) { burgerFactory = new FishBurgerFactory(); } //// 提供原料工廠 IIngredientFactory ingredientFactory = null; if (shopType == ShopType.Taipei) { ingredientFactory = new TaipeiIngredientFactory(); } else if (shopType == ShopType.NewYork) { ingredientFactory = new NewYorkIngredientFactory(); } else if (shopType == ShopType.Tokyo) { ingredientFactory = new TokyoIngredientFactory(); } //// 使用原料工廠提共的原料製作漢堡 return(burgerFactory.Create(ingredientFactory)); }