3、适配器模式

3、适配器模式  提供适配器的类,此类可以根据传参的类,执行不同的类的实现

 

 

namespace SJ.DesignMode
{
    /// <summary>
    /// 设计模式
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            IAdapter iadapterBig = new AdapterBigMan();
            IAdapter iadapterLittle = new AdapterLittleMan();

            Adapter adapter = new Adapter(iadapterLittle);
            adapter.Write();

      }
    }
  public class Adapter
    {
        private IAdapter _adapter = null;
        public Adapter(IAdapter adapter)
        {
            _adapter = adapter;
        }

        public void Write()
        {
            _adapter.Write();
        }
    }
    public interface IAdapter
    {
        void Write();
    }

    public class AdapterBigMan : IAdapter
    {
        public void Write()
        {
            Console.WriteLine("Big man !");
        }
    }

    public class AdapterLittleMan : IAdapter
    {
        public void Write()
        {
            Console.WriteLine("Little man !");
        }
    }

}    

  

posted @ 2021-12-21 14:14  艾特-天空之海  阅读(3)  评论(0编辑  收藏  举报