public static Food CreateFood(string type) { Food food = null; if (type.Equals("土豆肉丝")) { food = new ShreddedPorkWithPotatoes(); } else if (type.Equals("西红柿炒蛋")) { food = new TomatoScrambledEggs(); } return(food); }
/// <summary> /// 烧菜方法 /// </summary> /// <param name="type"></param> /// <returns></returns> public static Food Cook(string type) { Food food = null; // 客户A说:我想吃西红柿炒蛋怎么办? // 客户B说:那你就自己烧啊 // 客户A说: 好吧,那就自己做吧 if (type.Equals("西红柿炒蛋")) { food = new TomatoScrambledEggs(); } // 我又想吃土豆肉丝, 这个还是得自己做 // 我觉得自己做好累哦,如果能有人帮我做就好了? else if (type.Equals("土豆肉丝")) { food = new ShreddedPorkWithPotatoes(); } return(food); }