c++设计模式:适配器模式
2024-09-06 11:53:52
1.主要思想:将一个类的接口转换成客户希望的另外一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。
对于不同的客户我们可以这样使用适配器模式。
2.实现方法:
#include<iostream>
using namespace std; // "ITarget"
class Target
{
public:
// Methods
virtual void Request(){};
}; // "Adaptee"
class Adaptee
{
public:
// Methods
void SpecificRequest()
{
cout<<"Called SpecificRequest()"<<endl;
}
}; // "Adapter"
class Adapter : public Adaptee, public Target
{
public:
// Implements ITarget interface
void Request()
{
// Possibly do some data manipulation
// and then call SpecificRequest
this->SpecificRequest();
}
}; int main()
{
// Create adapter and place a request
Target *t = new Adapter();
t->Request(); return ; }
最新文章
- 试图加载格式不正确的程序。 (异常来自HRESULT:0x8007000B)
- iOS AFOAuth2Manager使用心得
- css学习中的一些英文单词
- TCP/IP 端口号大全
- 依赖注入Bean属性
- DOM 节点实例操作
- SurfaceView绘图机制
- 自定义清除重复uses-permission申明的AS插件
- JMeter怎么在get URL请求、POST请求中添加动态参数用于服务器段安全验证
- Java-List泛型的用处(能够使用传入泛型对象的方法)
- Quirks模式是什么?它和Standards模式有什么区别
- 【Jquery系列】详解Jquery对象和Dom对象
- 强化学习(五)用时序差分法(TD)求解
- Nginx从入门到实践(二)
- JAVA项目中文件重命名方式
- vue 图片切换动态绑定
- __AFO
- window7开启Administrator账户
- Linux下Oracle常用命令
- extends android.view.ViewGroup两种实现
热门文章
- 0704 Process继承实现多进程、Pool进程池,进程间通过队列通信,Pool实现多进程实现复制文件
- 字符串——cf1109B
- eclipse查看源码的配置
- NPM 使用介绍(包管理工具,解决NodeJS代码部署上的很多问题)
- hexo next中遇到的bug,引发出的关于jquery中click()函数和on("click",function())的区别
- Spring Boot 发布 jar 包转为 war 包秘籍。
- 2_2.springboot2.x配置之自动配置原理
- SSM三大框架的运行流程、原理、核心技术详解
- nginx 配置文件备份 nginx.conf and vhosts
- linux centos&;Ubuntu&;RedHat更换软件源