public static Food Cook(string type) { Food food = null; switch (type) { case "西红柿炒蛋": food = new TomatoScrambleEggs(); break; case "土豆肉丝": food = new ShreddedPorkWithPotatoes(); break; } return food; }
public static Food CreateFood(string type) { Food food = null; switch (type) { case "土豆肉丝": food = new TomatoScrambleEggs(); break; case "西红柿炒蛋": food = new TomatoScrambleEggs(); break; default: break; } return(food); }