#include <iostream>
using namespace std;
class ProductAbase
{
public:
ProductAbase(){}
virtual ~ProductAbase(){}
virtual void Printf() = 0;
};
class Product1 : public ProductAbase
{
public:
void Printf()
{
cout << "Product1::Printf()" << endl;
}
};
class Product2 :public ProductAbase
{
public:
void Printf()
{
cout << "Product2::Printf()" << endl;
}
};
class ProductBbase
{
public:
virtual void Printf() = 0;
};
class Product3 : public ProductBbase
{
public:
void Printf()
{
cout << "Product3::Printf()" << endl;
}
};
class Product4 : public ProductBbase
{
public:
void Printf()
{
cout << "Product4::Printf()" << endl;
}
};
class Factory
{
public:
Factory(){}
virtual ~Factory(){}
virtual ProductAbase* GetProductA() = 0;
virtual ProductBbase* GetProductB() = 0;
};
class Factory1 : public Factory
{
public:
ProductAbase* GetProductA()
{
return new Product1();
}
ProductBbase* GetProductB()
{
return new Product3();
}
};
class Factory2 : public Factory
{
public:
ProductAbase* GetProductA()
{
return new Product2();
}
ProductBbase* GetProductB()
{
return new Product4();
}
};
int main()
{
Factory *fa = new Factory1();
ProductAbase *pa = fa->GetProductA();
pa->Printf();
ProductBbase *pb = fa->GetProductB();
pb->Printf();
fa = new Factory2();
pa = fa->GetProductA();
pa->Printf();
pb = fa->GetProductB();
pb->Printf();
return 0;
}