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


  • 相关阅读:
    Count and Say
    Valid Sudoku
    Find First and Last Position of Element in Sorted Array
    Search in Rotated Sorted Array
    Longest Valid Parentheses
    web前端中文教程库
    三代基因组拼接软件--Falcon篇
    使用ThreadPoolExecutor并行执行独立的单线程任务
    python中的计时器:timeit
    Python教程
  • 原文地址:https://www.cnblogs.com/mikechang/p/1709028.html
Copyright © 2011-2022 走看看