适配器模式,Adapter
来源:互联网 发布:怎么把微店搬到淘宝 编辑:程序博客网 时间:2024/06/03 20:47
适配器的定义是:
把一个类的接口转换成客户想要的另一个接口。让多个不兼容接口的类能够协作。
其UML类图的示例如下:
在这个模式中,参与者包括:
- Target:定义Client要用到的特定领域的接口。
- Adapter:把Adaptee接口适配到Target接口上。
- Adaptee:定义一个现存的需要适配的接口。
- Client:把符合Target接口的对象协作起来。
实现代码:
public class Client{ private ITarget target; public Client(ITarget target) { this.target = target; } public void MakeRequest() { target.MethodA(); }} public interface ITarget{ void MethodA();} public class Adapter : Adaptee, ITarget{ public void MethodA() { MethodB(); }} public class Adaptee{ public void MethodB() { Console.WriteLine("MethodB() is called"); }}
- 允许系统使用另一个系统中不兼容的类。
- 允许相对独立的新系统和老系统之间相互通信。
- Ado.Net SqlAdapter, OracleAdapter, MySqlAdapter都是很好的例子。
0 0
- Adapter模式 适配器模式
- 适配器模式(Adapter)
- 适配器模式(Adapter)
- 适配器(Adapter)模式
- 适配器模式(Adapter Pattern)
- ADAPTER(适配器)模式
- 适配器模式(adapter)
- Adapter适配器模式
- 适配器(Adapter)模式
- 适配器模式(Adapter Pattern)
- Adapter(适配器)模式
- 适配器模式(adapter)
- 适配器模式(Adapter)
- 适配器模式(Adapter)
- 适配器模式(Adapter)
- 适配器模式 Adapter Pattern
- Adapter 适配器模式
- 适配器模式(Adapter)
- uva 10555 - Dead Fraction)(数论)
- 防止非法登录的模块(用过滤器过滤相应的文件夹)
- 委托,事件和反射
- linux下Oracle数据库实例开机自启动设置
- poj3417 Network 离线LCA + 树形dp
- 适配器模式,Adapter
- canvas.translate(x,y)一点新的认识
- Android笔记之 TTS中文发音
- LSM分别苹果和桔子
- 【#248_DIV2】-A B C
- 作为IT宅,OpenEIM 习惯了 Windows 的用户
- 约瑟夫环问题的数学分析解
- cocos2d-x实现Android版本的sdk的思路见解-----------------cocos2d-x3.0正式版本(7.4)
- Codeforces 29D Ant on the Tree 树的遍历 dfs序