设计模式-结构-Adapter(适配器)模式
情景1:项目中采用的第三方库和 本程序 的接口不一致,为了达到一致,可用适配器模式
情景2: 一个功能 由多个不相干的 多个功能组合而成,
适配器模式有2种类别:对象模式和 类模式
类模式:采用继承方式复用Adaptee
对象模式:采用组合复用Adaptee

class Target
{
public:
virtual void Request()
{
}
};
class Adaptee
{
public:
void SpecificRequest()
{
cout << __FUNCTION__ << endl;
}
};
// 类模式
class Adapter :public Target, public Adaptee
{
public:
void Request()override
{
Adaptee::SpecificRequest();
}
};
// 对象模式
class Adapter1 :public Target
{
public:
void Request()override
{
adaptee.SpecificRequest();
}
private:
Adaptee adaptee;
};
int main(int argc, char *argv[])
{
Target * target = new Adapter1;
target->Request();
system("pause");
return 0;
}