#define win 0
#define mac 1
#include <iostream>
using namespace std;
class button
{
public:
button(){}
virtual void createbutton()=0;
};
class macbutton : public button
{
public:
macbutton(){}
virtual void createbutton(){cout<<"macbutton"<<endl;}
};
class winbutton : public button
{
public:
winbutton(){}
virtual void createbutton(){cout<<"winbutton"<<endl;}
};
class simplefactory
{
public:
simplefactory(){}
button *createproduct(int ID);
button *createmacproduct();
button *createwinproduct();
};
button *simplefactory::createproduct(int ID)
{
if (ID==win)
return new winbutton;
if (ID==mac)
return new macbutton;
}
button *simplefactory::createwinproduct()
{
return new winbutton;
}
button *simplefactory::createmacproduct()
{
return new macbutton;
}
int main()
{
simplefactory fc;
button *bt=fc.createproduct(win);
bt->createbutton();
delete bt;
system("pause");
return 0;
}