简单工厂模式
/// <summary> /// 简单工厂类 /// </summary> public class FoodSim { public static Food CreateFood(string str) { Food food = null; if (str == "C1") { food = new C1(); } else if (str == "C2") { food = new C2(); } return food; } } public abstract class Food { public abstract void Print(); } public class C1 : Food { public override void Print() { Console.WriteLine("C1"); } } public class C2 : Food { public override void Print() { Console.WriteLine("C2"); } }