Example #1
0
        public void Main()
        {
            // 顾客想点一份番茄炒蛋
            Food2 food1 = FoodSimpleFactory.CreateFood("番茄炒蛋");

            food1.Print();

            // 顾客想点一份土豆炒肉
            Food2 food2 = FoodSimpleFactory.CreateFood("土豆肉丝");

            food2.Print();
        }
Example #2
0
        public static Food2 CreateFood(string type)
        {
            Food2 food = null;

            if (type.Equals("番茄炒蛋"))
            {
                food = new TomatoScrambledEggs2();
            }
            else if (type.Equals("土豆肉丝"))
            {
                food = new ShreddedPorkWithPotatoes2();
            }
            return(food);
        }