1、简单工厂
1、简单工厂 (调用静态方法实例化需要的类)
class Program { static void Main(string[] args) { //1、简单工厂 IMan man = Factory.Create(FactoryType.Student); man.Go(); } } public class Factory { public static IMan Create(FactoryType factoryType) { switch (factoryType) { case 0: return new Student(); default: return new Teacher(); } } } public enum FactoryType { Student =0, Teacher =1 } public class Student:IMan { public void Go() { Console.WriteLine("Student go !"); } } public class Teacher : IMan { public void Go() { Console.WriteLine("Teacher go !"); } }