简单工厂模式有三个角色: 工厂、抽象产品、具体产品
1.抽象产品
public abstract class Car { public abstract void MingDi(); }
2.具体产品
public class BenzCar:Car { public ovvried MingDi() { Conslose.WriteLine("我是大奔,嗡嗡"); } }
3.工厂
public class Factory { public static Car CreateCarInstance(string CarName) { switch(carName) { case "Benz": return new BenzCar(); break; case "Havar": return new HavarCar(); break; default: return null; } } }
4.具体实现
public class Program { static void Main(string[] args) { Car benzCar = Factory.CreateCarInstance(Benz); benzCar.MingDi(); Console.ReadKey(); } }