设计模式_适配器
来源:互联网 发布:在线影视源码 编辑:程序博客网 时间:2024/06/05 08:22
//类适配器#include<memory>#include<iostream>using namespace std;class Target { public: virtual void request(){ cout << "Target::Request"<<endl; }};class Adaptee{public: void SpecificRequest(){ cout << "adaptee::SpecificRequest()"<<endl; }};class Adapter : public Target , Adaptee{public: void request(){ Adaptee::SpecificRequest (); }};int main(int argc, char *argv[]){ auto_ptr<Target> tarobj ( new Adapter() );//适配器就是引入中间类进行后台链接 //Target *tarobj = new Adapter(); tarobj->request (); return 0;}
//对象适配器(比类适配器常用)#include<iostream>#include<memory>using namespace std;class Target{public: Target() {} virtual ~Target(){ cout <<"delete target"<<endl; } virtual void Request(){ cout << "Target request" << endl; }};class Adaptee{public: Adaptee() {} void SpecialRequest(){ cout << "Adaptee::request" <<endl; }};class Adapter : public Target{public: Adapter() : m_Adaptee(new Adaptee()){} ~Adapter(){ if( m_Adaptee != NULL){ delete m_Adaptee; cout << "delete Adaptee"<<endl; m_Adaptee = NULL; } } void Request (){ m_Adaptee->SpecialRequest (); }private: Adaptee *m_Adaptee;};int main(int argc, char *argv[]){ auto_ptr<Target> tarobj (new Adapter()); tarobj->Request (); return 0;}
2 0
- 设计模式_适配器
- 设计模式:适配器模式
- 设计模式------适配器模式
- 设计模式:适配器模式
- 设计模式---适配器模式
- 设计模式 适配器模式
- 设计模式 - 适配器模式
- 设计模式--适配器模式
- 设计模式-适配器模式
- 设计模式------适配器模式
- 设计模式---适配器模式
- 设计模式- 适配器模式
- 设计模式 - 适配器模式
- 设计模式:适配器模式
- 适配器模式--设计模式
- 设计模式 - 适配器模式
- 设计模式-适配器模式
- 设计模式---适配器模式
- HDU 2620 - Ice Rain (数学)
- linux文件系统
- HDFS的基本概念
- uva 10404 Bachet's Game
- HDOJ 1027 Ignatius and the Princess II
- 设计模式_适配器
- 新年快乐,怀恋故乡
- Android Handler,Looper,Message
- 【翻译自mos文章】OUI 的log文件和trace文件的位置
- POJ 3667 Hotel (初遇线段树区间合并)
- 安装11.2.0.3时,OUI的log报错:"OUI-10066:Not All The Dependencies For The Component ... Could Be Found"
- 【翻译自mos文章】在11.2GI的安装过程中,当拷贝到远程节点时OUI 挂起(65%处)
- 【翻译自mos文章】在RHEL7或者OL7上安装11.2.0.4时遇到错误 “undefined reference to symbol ‘B_DestroyKeyObject’”
- 使用runInstaller 的executePrereqs选项来验证os是否符合oracle db software的安装要求