zoukankan      html  css  js  c++  java
  • 适配器模式

    1 类适配器

    代码
        using System;
        
    using System.Collections.Generic;
       
       
    interface Itest
        {
              
    void NewRequest();
        }
       

       
    class Method
       {
               
    public void OldRequest()
               {
                       
    //DO;
               }
       }
      

       
    class MethodAdpter:Method,Itest
       {
               
    public void NewRequest()
               {
                       
    this.OldRequest();
               }
       }
      

       
    public class MyClass
       {
               
    public static void Main()
               {
                       Itest mytest
    =new MethodAdpter();
                       mytest.NewRequest();
               }
       }

    2 对象适配器

    代码
        using System;
        
    using System.Collections.Generic;
       

        
    class Adaptee
        {
                
    public void OldRequest()
               {
                       
    //TODO:
               }
       }
      

       
    class Target
       {
               
    virtual public void NewRequest()
               {
              
               }
       }
      

       
    class Adapter:Target
       {
               
    private Adaptee adaptee=new Adaptee();
              
               
    override public void NewRequest()
               {
                       adaptee.OldRequest();
               }
       }
      

       
    public class MyClass
       {
               
    public static void Main()
               {
                       Target t
    =new Adapter();
                       t.NewRequest();
               }
       }


  • 相关阅读:
    [20180814]校内模拟赛
    [20180812]四校联考
    [20180811]校内模拟赛
    [20180613]校内模拟赛
    网络流24题小结
    最小费用最大流——小结1
    ASP.NET MVC 下拉框的传值的两种方式
    面向方面编程(AOP)
    NPOI操作Excel
    IIS负载均衡
  • 原文地址:https://www.cnblogs.com/mikechang/p/1709028.html
Copyright © 2011-2022 走看看