Design Pattern ->Adaptor
Layering & Contract Philosophy With additional indirection
Adaptee object just is as a member. Adaptee object just relies on Adapter object.
- class CAdaptee
- {
- public: void theExistingAndIncompatibleMethod(){ … } ;
- }
- class CTarget
- {
- public: virtual void theNewMethod() = ;
- }
- class CAdapter: public CTarget, CAdaptee
- {
- public: void theNewMethod()
- {
- this->theExistingAndIncompatibleMethod();
- };
- }
- class CAdapter: public CTarget
- {
- public: void theNewMethod()
- {
- CAdaptee object;
- object.theExistingAndIncompatibleMethod();
- };
- }
- class client
- {
- public: void operation()
- {
- CTarget *pTarget = new CAdapter; pTarget->theNewMethod();}
- }
Applicability
Use the Adapter pattern when
- you want to use an existing class having a incompatible method with the new interface from the one you want to use, and its interface does not match the one you need. You want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces.
- (object adapter only) you need to use several existing subclasses, but it's impractical to adapt their interface by subclassing/making as subclass every one. An object adapter can adapt the interface of its parent class.
Participants
- Target (Shape): defines the domain-specific interface that Client uses.
- Client (DrawingEditor): collaborates with objects conforming to the Target interface.
- Adaptee (TextView): defines an existing interface that needs adapting.
- Adapter (TextShape): adapt the interface of Adaptee to the Target interface.
Collaborations
- Clients call operations on an Adapter instance. In turn, the adapter calls Adaptee operations that carry out the request.
Design Pattern ->Adaptor的更多相关文章
- Design Pattern Adaptor 适配器设计模式
适配器设计模式是为了要使用一个旧的接口,或许这个接口非常难用,或许是和新的更新的接口不兼容,所以须要设计一个适配器类,然后就能够让新旧的接口都统一. 就是这种一个图: watermark/2/text ...
- 说说设计模式~大话目录(Design Pattern)
回到占占推荐博客索引 设计模式(Design pattern)与其它知识不同,它没有华丽的外表,没有吸引人的工具去实现,它是一种心法,一种内功,如果你希望在软件开发领域有一种新的突破,一个质的飞越,那 ...
- 设计模式(Design Pattern)系列之.NET专题
最近,不是特别忙,重新翻了下设计模式,特地在此记录一下.会不定期更新本系列专题文章. 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结. 使用 ...
- [转]Design Pattern Interview Questions - Part 4
Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, COR Pattern, Proxy Pattern, te ...
- [转]Design Pattern Interview Questions - Part 2
Interpeter , Iterator , Mediator , Memento and Observer design patterns. (I) what is Interpreter pat ...
- [转]Design Pattern Interview Questions - Part 3
State, Stratergy, Visitor Adapter and fly weight design pattern from interview perspective. (I) Can ...
- [转]Design Pattern Interview Questions - Part 1
Factory, Abstract factory, prototype pattern (B) What are design patterns? (A) Can you explain facto ...
- design pattern
1. visitor design pattern http://butunclebob.com/ArticleS.UncleBob.IuseVisitor
- Design Pattern: Observer Pattern
1. Brief 一直对Observer Pattern和Pub/Sub Pattern有所混淆,下面打算通过这两篇Blog来梳理这两种模式.若有纰漏请大家指正. 2. Use Case 首先我们来面 ...
随机推荐
- 基础线程机制--Daemon,sleep(),yield()
Daemon 守护线程是程序运行时在后台提供服务的线程,不属于程序中不可或缺的部分,当所有非守护进程执行完成时,程序也就终止,同时会杀死所有的守护进程.main()属于非守护线程.可以使用setD ...
- java 在web应用中获取本地目录和服务器上的目录不一致的问题
先来讲讲我所遇到的问题.最近有个新的项目添加新的功能. 修改之后部署到服务器上面发现取到classpath目录跑到别的地方去了.在本地测试却正常. 当时毛的着火了.硬是想不懂什么问题. 终于发现了这个 ...
- MySQL 关联查询 外连接 { LEFT| RIGHT } JOIN
左外连接: (以左表为基准)两张表做连接的时候,在连接条件不匹配的时候留下左表中的数据,而右表中的数据以NULL填充例:使用左连接把学生的数据全取出来,该学生没有学院信息的用NULL填充 mysql& ...
- python BeautifulSoup基本用法
#coding:utf-8 import os from bs4 import BeautifulSoup #jsp 路径 folderPath = "E:/whm/google/src_j ...
- git学习---去除版本控制
本地这样去除文件夹 node_modules 的版本关联:执行:git rm -r --cached "node_modules/"提交: git commit -am 'remo ...
- js css 点亮 星级评分
利用css 和 js 实现星级评分 <!DOCTYPE html> <html lang="en"> <head> <meta chars ...
- idea(1)-idea初装
1.安装插件 Alibaba Java Coding Guidelines Free Mybatis plugin MyBatis Log Plugin Lombok pluginGsonFormat ...
- 练习五十六:for循环
某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换 方法一: def o ...
- c#之GDI简单实现代码及其实例
作业:文档形式 3到5页理解 1.理解 2.源代码解释(1到2页) 3.实现效果 项目地址: https://github.com/zhiyishou/polyer Demo:https://zhiy ...
- phpstrom的xdebug开启和yii2下的分页的链接
phpstrom的xdebug开启 1.修改php.ini文件(修改完重启apaceh) xdebug.remote_enable = onxdebug.idekey= PHPSTROM [注意:远程 ...