适配器模式

来源:互联网 发布:python虚拟主机 编辑:程序博客网 时间:2024/05/20 21:57
#include<iostream>
using namespace std;


class Target
{
public:
virtual void Request()
{
cout<<"普通请求"<<endl;
}
};


//需要适配的
class Adaptee
{
public:
void SpecialRequest()
{
cout<<"特殊请求"<<endl;
}
};




class Adapter:public Target
{
private:
Adaptee* adaptee()
{
return new Adaptee();
}


public:
void Request()
{
adaptee()->SpecialRequest();
}
};




int main()
{
Target* target=new Target();
target->Request();
target=new Adapter();
target->Request();
return 0;
}
0 0
原创粉丝点击