#include<iostream>
using namespace std;
class PowerSupply220v
{
public:
virtual void use_power220v()
{
cout << "I'm 220v power, please use." << endl;
}
};
class PowerSupply18v
{
public:
virtual void use_power18v()
{
cout << "I'm 18v power, please use." << endl;
}
};
class Adapter: public PowerSupply18v
{
public:
Adapter(PowerSupply220v* powerSupply)
{
m_powersupply = powerSupply;
}
void use_power18v()
{
m_powersupply->use_power220v();
cout << "Adapter is adaptering 220v to 18v" << endl;
cout << "I'm 18v power, please use." << endl;
}
PowerSupply220v *m_powersupply;
};
int main()
{
PowerSupply220v *powerSupply220V = NULL;
Adapter *adapter = NULL;
powerSupply220V = new PowerSupply220v;
adapter = new Adapter(powerSupply220V);
adapter->use_power18v();
delete powerSupply220V;
delete adapter;
return 0;
}
设计模式之-----适配器模式
最新推荐文章于 2024-04-20 10:23:16 发布