#include<iostream>
using namespace std;
class Current18v
{
public:
virtual void useCurrent18v() = 0;
};
class Current220v
{
public:
void useCurrent220v()
{
cout << "我是220v欢迎使用!" << endl;
}
};
class Adapter :public Current18v
{
public:
Adapter(Current220v*current)
{
m_current = current;
}
virtual void useCurrent18v()
{
cout << "适配器适配220v" << endl;
m_current->useCurrent220v();
}
private:
Current220v *m_current;
};
void main()
{
Current220v *current220v = NULL;
Adapter*adapter = NULL;
current220v = new Current220v;
adapter = new Adapter(current220v);
adapter->useCurrent18v();
delete current220v;
delete adapter;
}
适配器模式
最新推荐文章于 2024-09-24 17:25:47 发布