为其他对象提供一种代理以控制对这个对象的访问。这样实现了业务和核心功能分离。
#include<iostream>
using namespace std;
class IFactory{
virtual void makeProduct()=0;
};
class PhoneFactory : public IFactory{
virtual ~PhoneFactory(){}
PhoneFactory(){}
void makeProduct()
{
cout<<"生产手机"<<endl;
}
};
class FoxconnProxy : public IFactory{
virtual ~FoxconnProxy(){}
FoxconnProxy(IFactory *real)
{
m_real = real;
}
void makeProduct()
{
m_real->makeProduct();
}
private:
IFactory *m_real;
};