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();
               }
       }


  • 相关阅读:
    【windows 10 安装docker for windows】
    【windows本地修改git账号、路径信息】
    【echarts】简单使用流程(java)
    【MySql】explain
    【thymeleaf-标签】th:with
    【MongoDB】Windows:安装与启动
    【thymeleaf-标签】th:if
    Thread类中interrupt()、interrupted()和isInterrupted()方法详解
    java中的锁
    LinkedList集合详解
  • 原文地址:https://www.cnblogs.com/mikechang/p/1709028.html
Copyright © 2011-2022 走看看