/*
** FileName : FactoryMethodPatternDemo
** Author : Jelly Young
** Date : 2013/11/18
** Description : More information, please go to http://www.1sucai.cn
*/
#include <iostream>
using namespace std;
class Product
{
public:
virtual void Show() = 0;
};
class ProductA : public Product
{
public:
void Show()
{
cout<< "I'm ProductA"<<endl;
}
};
class ProductB : public Product
{
public:
void Show()
{
cout<< "I'm ProductB"<<endl;
}
};
class Factory
{
public:
virtual Product *CreateProduct() = 0;
};
class FactoryA : public Factory
{
public:
Product *CreateProduct()
{
return new ProductA ();
}
};
class FactoryB : public Factory
{
public:
Product *CreateProduct()
{
return new ProductB ();
}
};
int main(int argc , char *argv [])
{
Factory *factoryA = new FactoryA ();
Product *productA = factoryA->CreateProduct();
productA->Show();
Factory *factoryB = new FactoryB ();
Product *productB = factoryB->CreateProduct();
productB->Show();
if (factoryA != NULL)
{
delete factoryA;
factoryA = NULL;
}
if (productA != NULL)
{
delete productA;
productA = NULL;
}
if (factoryB != NULL)
{
delete factoryB;
factoryB = NULL;
}
if (productB != NULL)
{
delete productB;
productB = NULL;
}
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有