适配器模式(一)
来源:互联网 发布:游族网络是双休么 编辑:程序博客网 时间:2024/06/02 00:03
适配器模式:(有时候也称包装样式或者包装)将一个类的接口适配成用户所期待的。一个适配允许通常因为接口不兼容而不能在一起工作的类工作在一起,做法是将类自己的接口包裹在一个已存在的类中。
UML类图:
1.pencil类:
package com.jxufe.adapter;public class Pencil { public void usingWriteByPencil(){ System.out.println("使用铅笔写字"); }}
2.pen接口:
package com.jxufe.adapter;/** * 用户所需要的* @author jack* @version 创建时间:2016年4月25日 下午7:29:30* */public interface Pen {/** * 使用圆珠笔 */ public void usingPenToWrite();}
3.adapter类:
package com.jxufe.adapter;public class Adapter implements Pen { private Pencil pencil; public Adapter(Pencil pencil){ this.pencil = new Pencil(); }public void usingPenToWrite() { pencil.usingWriteByPencil();}}
4.client类:
package com.jxufe.adapter;public class Client { private Pen pen;public Client(Pen pen){this.pen = pen;}public void writer(){pen.usingPenToWrite();}public static void main(String[] args) { Pencil pencil = new Pencil();Pen pen = new Adapter(pencil);Client client = new Client(pen);client.writer();}}
0 0
- 适配器模式(一)
- 适配器模式(一)
- 适配器模式(一)
- 同步适配器模式(一)
- 适配器模式(Adapter Pattern)(一):适配器模式介绍
- (结构型模式一)适配器模式
- 设计模式(一)之适配器模式
- 设计模式之接口型模式(一)----适配器模式
- 设计模式<一>适配器模式
- 设计模式<一>适配器模式
- 设计模式一日一练:适配器模式(Adapter)
- 设计模式初探(一)「适配器模式」
- 不兼容结构的协调——适配器模式(一):适配器模式概述
- 结构型设计模式(一)(适配器模式,桥接模式,组合模式,装饰模式)
- Java结构型设计模式-适配器(一)
- 每天一设计模式之适配器模式
- 小话设计模式一:适配器模式
- C++设计模式之适配器模式(一)
- spring通过注解实现声明式事务控制
- iOS界面卡顿之离屏渲染
- 47-引用计数与写时复制
- Eclipse使用jUnit4对MapReduce程序进行单元测试
- (干货) Android Volley框架源码详细解析
- 适配器模式(一)
- 48-PHP5.3的垃圾回收机制
- Android 监听电话---在多页面同时使用不产生影响的解决方法
- 【超强干货分享】蘑菇街App的组件化之路
- 49-内存管理中的cache
- 50-写时复制COW机制
- 葡萄城程序设计大赛
- 51-数组与链表
- swift干货集整理