Adapter模式

来源:互联网 发布:杭州淘宝g20怎么办 编辑:程序博客网 时间:2024/06/06 07:39

Adapter模式又叫适配器模式,顾名思义,这个模式就是把一个不能用的东西“适配”成可以用的东西。

namespace DesignPatternConsoleApp{    public class Target    {        public virtual void DoSomethingForTarget()        {            //do something here            Console.WriteLine("virtual");        }    }    public class Adaptee    {        public void DoSomethingForAdaptee()        {            //do something here            Console.WriteLine("Adaptee");        }    }    public class Adapter : Target    {        private Adaptee adaptee = new Adaptee();//got a reference of adaptee        public override void DoSomethingForTarget()        {            adaptee.DoSomethingForAdaptee();//here adapt the adaptee to the target exactly        }    }}


 

原创粉丝点击