• 设计模式——适配器模式


    public interface Extends {
         void show();
         void show2();
    }

    public class SourceObj {
         void method() {
             System.out.println("父亲方法");
         }
    }

    //适配器对象

    public class AdapterObject implements Extends{
        
         private SourceObj source;
         public AdapterObject(SourceObj source) {
             this.source = source;
         }
         public void method() {
             source.method();
         }
        
         @Override
         public void show() {
             // TODO Auto-generated method stub
             System.out.println("接口show()");
         }

        @Override
         public void show2() {
             // TODO Auto-generated method stub
             System.out.println("接口show2()");
         }
        
    }

    //+继承关系

    public class Adapter extends SourceObj implements Extends{
        
         @Override
         public void show() {
             // TODO Auto-generated method stub
             System.out.println("接口show()");
         }

        @Override
         public void show2() {
             // TODO Auto-generated method stub
             System.out.println("接口show2()");
         }
        
    }

    //实现与调用

    Adapter adapter = new Adapter();
             adapter.method();
             adapter.show();
             adapter.show2();
            
             SourceObj sourceObj = new SourceObj();
             AdapterObject aObject = new AdapterObject(sourceObj);
             aObject.method();
             aObject.show();
             aObject.show2();

  • 相关阅读:
    python 标准库和第3方库的介绍
    delphi延时函数
    delphi控件的安装
    Hadoop 第一课:linux常用命令
    复习 struts1 开发步骤
    struts学习:传统方法完成struts注册表单校验与回显数据
    struts入门第一个案例
    Java Ant build.xml详解
    HTTP 方法:GET 对比 POST
    HTTP 返回的状态消息
  • 原文地址:https://www.cnblogs.com/macro-renzhansheng/p/12568478.html
Copyright © 2020-2023  润新知