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


  • 相关阅读:
    Android GzipOutputStream、GzipInputStream用法
    JAVA中String类的intern()方法的作用
    Android中解析XML
    Android 实现Xmpp工具类
    Android 用SSL构建安全的Socket
    Android ReentrantLock
    ReentrantLock与synchronized
    Android 使用MediaMetadataRetriever类获取视频第一帧及用法
    Android 关于android布局的两个属性dither和tileMode
    Hadoop MapReduce编程 API入门系列之倒排索引(二十四)
  • 原文地址:https://www.cnblogs.com/mikechang/p/1709028.html
Copyright © 2011-2022 走看看