标签:
/// <summary> /// FPC抽象类 /// </summary> public abstract class FPC { /// <summary> /// FPC生产抽象方法 /// </summary> public abstract void Produce(); } /// <summary> /// 生产GTL类 /// </summary> public class GTL : FPC { public override void Produce() { Console.WriteLine("GTL"); } } /// <summary> /// 生产GBL类 /// </summary> public class GBL : FPC { public override void Produce() { Console.WriteLine("GBL"); } } /// <summary> /// 生产GTS类 /// </summary> public class GTS : FPC { public override void Produce() { Console.WriteLine("GTS"); } } /// <summary> /// FPC抽象工厂类 /// </summary> public abstract class CreateFPC { /// <summary> /// FPC工厂方法 /// </summary> /// <returns></returns> public abstract FPC ProduceFPC(); } /// <summary> /// 生产GTL工厂类 /// </summary> public class CreateGTL : CreateFPC { //负责生产GTL public override FPC ProduceFPC() { return new GTL(); } } /// <summary> /// 生产GBL工厂类 /// </summary> public class CreateGBL : CreateFPC { /// <summary> /// 负责生产GBL /// </summary> /// <returns></returns> public override FPC ProduceFPC() { return new GBL(); } } /// <summary> /// 生产GTS工厂类 /// </summary> public class CreateGTS : CreateFPC { /// <summary> /// 负责生产GTS /// </summary> /// <returns></returns> public override FPC ProduceFPC() { return new GTS(); } }
调用:
CreateFPC a1a = new CreateGTL(); FPC fpca1a = a1a.ProduceFPC(); fpca1a.Produce();
标签:
原文地址:http://www.cnblogs.com/genesis/p/5153361.html