C++设计模式之适配器模式(改编自C++设计模式)
来源:互联网 发布:手机淘宝个人中心在哪 编辑:程序博客网 时间:2024/06/05 10:54
Adapter模式:
:将一个类的接口转化为客户希望的接口.
Good:使得原本由于接口不兼容而不能一起工作的那些类能够一起工作.
主要应用于希望复用一些现存的类,但是接口又与复用环境不相容的情况.
Pic:
Adapter Pattern(类模式)结构图
Adapter Pattern(对象模式)结构图
Code:
#include <iostream>using namespace std;class Target{public:virtual void Request(){cout << "普通的请求" << endl;}};//要适配的类class Adaptee{public:void SpecificalRequest(){cout << "特殊请求" << endl;}};//将Adaptee打包,从而实现与Target有相同接口class Adapter :public Target{private:Adaptee* ada;public:virtual void Request(){ada->SpecificalRequest();Target::Request();}Adapter(){ada = new Adaptee();}~Adapter(){delete ada;}};//客户端:int main(){Adapter * ada = new Adapter();ada->Request();delete ada;cin.get();return 0;}
0 0
- C++设计模式之适配器模式(改编自C++设计模式)
- C#--设计模式之适配器模式
- C++设计模式之抽象工厂模式(改编自C++设计模式)
- C++设计模式之单例模式(改编自C++设计模式)
- C++设计模式之建造者模式(改编自C++设计模式)
- C++设计模式之原型模式(改编自C++设计模式)
- C++设计模式之桥接模式(改编自C++设计模式)
- C++设计模式之装饰模式(改编自C++设计模式)
- 【设计模式】设计模式之适配器模式
- 设计模式 之 适配器模式
- 设计模式之适配器模式
- 设计模式之适配器模式
- 设计模式之适配器模式
- 设计模式之适配器模式
- 设计模式之适配器模式
- 设计模式之--适配器模式.
- 设计模式之适配器模式
- 设计模式之--适配器模式
- glibc detected
- jsp中写java代码的方式
- OC --- block
- windows7批量设置文件权限命令参数详解
- danci
- C++设计模式之适配器模式(改编自C++设计模式)
- js用fuction定义构造函数
- R in Action 学习笔记-边学边查
- 热电制冷器的优缺点
- 写一个新的xtype
- POJ 2676 锻炼码力:数独,精确覆盖的DLX
- git 获取远程分支
- 经验积累之C语言与汇编语言的区别
- Eclipse中jar包中文注释乱码