标签:
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace { interface FoodFactory { Burger CreateBurger(); Chicken CreateChicken(); Drink CreateDrink(); } class KFCFactory:FoodFactory { public Burger CreateBurger() { return new KFC_Burger(); } public Chicken CreateChicken() { return new KFC_Chicken(); } public Drink CreateDrink() { return new KFC_Drink(); } } class McDonaldsFactory:FoodFactory { public Burger CreateBurger() { return new McDonalds_Burger(); } public Chicken CreateChicken() { return new McDonalds_Chicken(); } public Drink CreateDrink() { return new McDonalds_Drink(); } } interface Food { void deal(); } class Burger:Food { public virtual void deal() { } } class Chicken:Food { public virtual void deal() { } } class Drink:Food { public virtual void deal() { } } class KFC_Burger:Burger { public override void deal() { Console.WriteLine("您的KFC汉堡"); } } class KFC_Chicken:Chicken { public override void deal() { Console.WriteLine("您的KFC炸鸡"); } } class McDonalds_Chicken:Chicken { public override void deal() { Console.WriteLine("您的麦当劳炸鸡"); } } class KFC_Drink:Drink { public override void deal() { Console.WriteLine("您的KFC饮料"); } } class McDonalds_Drink:Drink { public override void deal() { Console.WriteLine("您的麦当劳饮料"); } } class Client { static void Main(string[] args) { FoodFactory factory=new McDonaldsFactory(); Burger burger = factory.CreateBurger(); Chicken chicken = factory.CreateChicken(); Drink drink = factory.CreateDrink(); burger.deal(); chicken.deal(); drink.deal(); Console.ReadLine(); } } }
标签:
原文地址:http://www.cnblogs.com/123456yao/p/5097037.html