释蝉

博客园 首页 新随笔 联系 订阅 管理
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();
        }
    }
}

 

posted on 2020-04-01 15:07  释蝉  阅读(78)  评论(0编辑  收藏  举报