Java设计模式(9) —— 适配器
来源:互联网 发布:日本网络制式 编辑:程序博客网 时间:2024/06/05 19:26
Adapter
Intent
Convert the interface of a class into another interface clients expect.
Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
You want to use an existing class, and its interface does not match the one you need.
How to
Object Adapter
Class Adapter
Target
defines the domain-specific interface that Client uses.
Client
collaborates with objects conforming to the Target interface.
Adaptee
defines an existing interface that needs adapting.
Adapter
adapts the interface of Adaptee to the Target interface.
Known cases
Use third-party lib, but it doesn't satisfy the interface clients expect.
UML
对象适配器
类适配器
代码:
对象适配器
类适配器
区别:
(1)在Java中不允许多重继承,所以有些情况下必须得用“对象适配器”;比如:一个Adapter要实现一个抽象类的接口,而Adaptee也是一个类,这只能用“对象适配器”。
(2)对象适配器比类适配器更灵活,可以为对象适配器配置不同子类的Adaptee
- Java设计模式(9) —— 适配器
- JAVA设计模式——适配器模式
- java设计模式——适配器模式
- JAVA设计模式——适配器模式
- Java设计模式——适配器模式
- Java设计模式——适配器模式
- Java设计模式——适配器模式
- Java设计模式——适配器模式
- Java设计模式——适配器模式
- Java设计模式——适配器模式
- Java设计模式——适配器模式
- Java设计模式——适配器模式
- Java设计模式——适配器模式
- Java设计模式——适配器模式
- Java设计模式—适配器模式
- java设计模式—适配器模式
- Java设计模式—适配器模式
- Java设计模式学习—适配器模式
- Windows中的快捷键
- 潘多拉网吧防火墙 1.0 双线破解
- 如何操作串口和zigbee通信
- NAND和NOR flash的区别
- vc中如何调用dll函数
- Java设计模式(9) —— 适配器
- WIN32用户界面设计基础之Cursor篇(转)
- 裁剪定制Qt库
- gzip 完全理解(0)------写在前面的话
- HTTP调试工具:Fiddler的使用方法介绍
- ”Warning: no message line prompt for ID 0xE001“产生原因
- symbian活动对象(AO),活动调度器(AS),活动服务提供者(ASP)
- 09七夕已过
- 系统分层