适配器模式
2016-03-22 18:06
232 查看
适配器模式分为三种:
1.类的适配器模式
2.对象的适配器模式
3.接口的适配器模式
/** * * @author: muyichun * @date : 2016年3月22日16:11:11 * @function: 适配器模式 */ public class Main{ public static void main(String[] args) { Adapter target = new Adapter(); target.method1(); target.method2(); } } class Source{ public void method1(){ System.out.println("method1"); } } interface Targetable{ public void method1(); //原类中的方法相同 public void method2(); //新类的方法 } class Adapter extends Source implements Targetable{ @Override public void method2() { System.out.println("method2"); } }
此代码为类的适配器模式,另外两种类同。 对象适配器模式:将Source作为Adapter的参数传递进去。 接口适配器模式:类似于even事件里的监听adapter类,达到实现那些不必要的方法。
相关文章推荐
- org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class ‘XXX’
- PHPEXCEL在thinkphp中封装成类使用
- eclipse的使用总结
- 手打struts知识点
- EvenBus3.0中文翻译(三)Delivery Threads (ThreadMode)
- 操作系统--命令解释程序_1
- Javascript写的10进制与16进制互转
- Linq to sql 自定义类型
- 法线变换
- BFS和DFS优先搜索算法
- 关于手机连不上拼命循环弹出“Connection attempts: x远程主机强迫关闭了一个现有的连接 ”的解决办法
- 正版win8平均15分钟蓝屏一次。显示critical structure corruption(ntfs.sys)
- NodeJS - Error: The specified procedure could not be found
- Hibernate 以流的方式获取数据
- 手写字体识别 --MNIST数据集
- Linux中使用C语言实现基于UDP协议的Socket通信示例
- POJ 1543 Perfect Cubes
- Android实战技巧:消息循环与Looper
- POJ 1426 Find The Multiple (BFS)
- Linux查看文件最后几行的命令,日志的福音啊