C++设计模式:适配器模式(十四)
// 老接口
class IAdaptee {
public:
virtual void foo(int data) = 0;
virtual int bar() = 0;
};
class Adaptee:public IAdaptee {
public:
virtual void foo(int data) override{
}
virtual int bar() override{
}
};
// 目标接口
class ITarget{
public:
virtual void process() = 0;
};
class Adapter: public IAdaptee{
private:
IAdaptee* adaptee; // 多态
public:
Adapter(IAdaptee *iAdaptee): adaptee(iAdaptee){
}
virtual void process() override{
// ...
int data = adaptee->bar();
adaptee->foo(data);
// ...
}
};