#include <iostream>
using namespace std;
class LeiFeng
{
public:
virtual void Sweep()
{
cout<<"扫地"<<endl;
}
virtual void Wash()
{
cout<<"洗衣"<<endl;
}
virtual void BuyRice()
{
cout<<"买米"<<endl;
}
};
class Undergraduate:public LeiFeng
{
public:
void Sweep()
{
cout<<"大学生扫地"<<endl;
}
void Wash()
{
cout<<"大学生洗衣"<<endl;
}
void BuyRice()
{
cout<<"大学生买米"<<endl;
}
};
class Volunter:public LeiFeng
{
public:
void Sweep()
{
cout<<"志愿者扫地"<<endl;
}
void Wash()
{
cout<<"志愿者洗衣"<<endl;
}
void BuyRice()
{
cout<<"志愿者买米"<<endl;
}
};
class IFactory
{
public:
virtual LeiFeng* CreateLeiFeng(){return NULL;};
};
class UndergraduateFactory:public IFactory
{
public:
LeiFeng* CreateLeiFeng() override
{
return new Undergraduate();
}
};
class VolunterFactory:public IFactory
{
public:
LeiFeng* CreateLeiFeng() override
{
return new Volunter();
}
};
int main()
{
IFactory* factory = new VolunterFactory();
LeiFeng* leifeng = factory->CreateLeiFeng();
leifeng->BuyRice();
leifeng->Sweep();
leifeng->Wash();
getchar();
return 0;
}
转发至微博
转发至微博