设计模式05_抽象工厂模式

学习设计模式笔记之_抽象模式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 抽象__汉堡可乐
{
    interface Hanbger
    {
        void buyhan();
    }
    interface kele
    {
        void buykele();
    }
    class buykele_M:kele
    {
        public void buykele()
        {
            Console.WriteLine("在麦当劳买可乐");
        }
    }
    class buykele_K:kele
    {
        public void buykele()
        {
            Console.WriteLine("在肯德基买可乐");
        }
    }
    class buyhan_M:Hanbger
    {
        public void buyhan()
        {
            Console.WriteLine("在麦当劳买汉堡包");
        }
    }
    class buyhan_K:Hanbger
    {
        public void buyhan()
        {
            Console.WriteLine("在肯德基买汉堡包");
        }
    }

    interface fastfood_factory
    {
        Hanbger get_hanber();
        kele get_kele();
    }
    class MDL:fastfood_factory
    {
        public Hanbger get_hanber()
        {
            return new buyhan_M();
        }
        public kele get_kele()
        {
            return new buykele_M();
        }
    }
    class KDJ : fastfood_factory
    {
        public Hanbger get_hanber()
        {
            return new buyhan_K();
        }
        public kele get_kele()
        {
            return new buykele_K();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            fastfood_factory food_ = new KDJ();
            Hanbger H = food_.get_hanber();
            kele K = food_.get_kele();
            H.buyhan();
            K.buykele();
            Console.Read();
        }
    }
}

运行结果


posted on 2016-06-02 14:58  胖胖的乓乓  阅读(125)  评论(0编辑  收藏  举报

导航