namespace ConsoleApp6 { class Program { static void Main(string[] args) { FactoryBase shanghai=new ShangHiaFactory(); YaBo yaBo = shanghai.CreateYaBo(); yaBo.Say(); Console.ReadKey(); } } //鸭架基类 public abstract class YaBo { public abstract void Say(); } public class ShangHaiYaBo : YaBo { public override void Say() { Console.WriteLine("上海鸭脖!"); } } public class NanChangYaBo : YaBo { public override void Say() { Console.WriteLine("南昌鸭脖!"); } } //鸭架基类 public abstract class Yajia { public abstract void Say(); } public class ShangHaiYaJia : Yajia { public override void Say() { Console.WriteLine("上海鸭架!"); } } public class NanChangYaJia : Yajia { public override void Say() { Console.WriteLine("南昌鸭架!"); } } public abstract class FactoryBase { public abstract YaBo CreateYaBo(); public abstract Yajia CreateYaJia(); } //上海公司 public class ShangHiaFactory : FactoryBase { public override YaBo CreateYaBo() { return new ShangHaiYaBo(); } public override Yajia CreateYaJia() { return new ShangHaiYaJia(); } } //上海公司 public class NanChangFactory : FactoryBase { public override YaBo CreateYaBo() { return new ShangHaiYaBo(); } public override Yajia CreateYaJia() { return new ShangHaiYaJia(); } } }