<span style="font-family: Arial, Helvetica, sans-serif;">class product</span>
{
public:
virtual void show() = 0;
}
class productA: public product
{
public:
void show(){ cout << "productA" << std::endl;}
}
class productB : public product
{
public:
void show(){ cout << "productB" << std::endl;}
}
class Factroy
{
public:
virtual product* createProduct() = 0;
}
class FactroyA : Factroy
{
public:
product* createProduct(){ return new productA;}
}
class FactroyB: Factory
{
public:
product* createProduct(){return new productB;}
}
工厂能够随产品的需要而扩展