是一种结构型设计模式,使得不兼容的接口一起工作
原始使用
1 | #include <iostream> |
类适配器
「类适配器」
以多继承方式实现。
Target: 客户端期望接口类
Adaptee: 实际需要的功能类
Adapter: 将接口类与功能类衔接的适配器类
Client: 客户端代码
1 | #include <iostream> |
对象适配器
「对象适配器」
在适配器类中,包装适配者(Adaptee)接口。
Target: 客户端期望接口类
Adaptee: 实际需要的功能类
Adapter: 将接口类与功能类衔接的适配器类
Client: 客户端代码
1 | #include <iostream> |