public Pizza(IIngredientFactory ingredientFactory) { IngredientFactory = ingredientFactory; Dough = IngredientFactory.CreateDough(); Sauce = IngredientFactory.CreateSauce(); Meat = IngredientFactory.CreateMeat(); Veggie = IngredientFactory.CreateVeggie(); }
/// <summary> /// 这里为 模拟的 客户端的 消费代码. /// /// 客户端 对于 不同体系的产品。 /// 消费代码是一样的。 /// </summary> /// <param name="gardener"></param> private static void Demo(IGardener gardener) { IFruit fruit = gardener.CreateFruit(); fruit.Plant(); fruit.Grow(); fruit.Harvest(); IVeggie veggie = gardener.CreateVeggie(); veggie.Plant(); }
public void SpawnVeggies(ProduceRequirements requirements) { factory = FactoryProducer.GetFactory(FactoryType.Veggie); if (requirements.green) // If it's a green vegetable, spawn Broccoli { GameObject produce = Instantiate(broccoliPrefab); outputText.text = "Created broccoli."; m_Broccoli = factory.GetVeggie(VeggieType.Broccoli); m_Broccoli.Vegetate(); } else if (requirements.yellow) // If it's a yellow vegetable, spawn a Potato { GameObject produce = Instantiate(potatoPrefab); outputText.text = "Created a potato."; m_Potato = factory.GetVeggie(VeggieType.Potato); m_Potato.Vegetate(); } else if (requirements == null) // if no requirements are given, spawn all vegetables //This is the case for when the user presses the vegetable key { m_Carrot = factory.GetVeggie(VeggieType.Carrot); m_Broccoli = factory.GetVeggie(VeggieType.Broccoli); m_Potato = factory.GetVeggie(VeggieType.Potato); m_Carrot.Vegetate(); m_Broccoli.Vegetate(); m_Potato.Vegetate(); } else // Otherwise spawn a carrot { GameObject produce = Instantiate(carrotPrefab); outputText.text = "Created a carrot."; m_Carrot = factory.GetVeggie(VeggieType.Carrot); m_Carrot.Vegetate(); } }
public Sandwich(IBread bread, IMeat meat, IVeggie veggie) { _bread = bread; _meat = meat; _veggie = veggie; }