#define win 0
#define mac 1
#include <iostream>
using namespace std;

class button
{
public:
    button(){}
    virtual ~button(){}
    virtual void showbutton()=0;
};

class winbutton : public button
{
public:
    winbutton(){}
    virtual ~winbutton(){}
    void showbutton(){cout<<"win button"<<endl;}
};

class macbutton : public button
{
public:
    macbutton(){}
    virtual ~macbutton(){}
    void showbutton(){cout<<"mac button"<<endl;}
};

class factory
{
public:
    factory(){}
    virtual ~factory(){}
    virtual button *createbutton()=0;
};

class winfactory : public factory
{
public:
    winfactory(){}
    virtual ~winfactory(){}
    button *createbutton(){return new winbutton;}
};

class macfactory : public factory
{
public:
    macfactory(){}
    virtual ~macfactory(){}
    button *createbutton(){return new macbutton;}
};

int main()
{
    factory *fc=new winfactory;
    button *bt=fc->createbutton();
    bt->showbutton();
    delete bt;
    delete fc;

    fc=new macfactory;
    bt=fc->createbutton();
    bt->showbutton();
    delete bt;
    delete fc;

    system("pause");
    return 0;
}

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2021-07-30
  • 2021-12-14
  • 2022-01-26
  • 2021-07-11
  • 2021-05-20
  • 2021-11-25
猜你喜欢
  • 2022-12-23
  • 2021-05-31
  • 2021-09-06
  • 2021-06-01
  • 2022-01-04
  • 2021-10-16
  • 2021-10-23
相关资源
相似解决方案