设计模式-工厂模式
来源:互联网 发布:中标麒麟数据库 编辑:程序博客网 时间:2024/05/22 06:06
//Factory.h#pragma once class Product;class Factory{public:virtual ~Factory()=0;virtual Product* CreateProduct() = 0;protected:Factory();private:};class BeverageFactory : public Factory{public:BeverageFactory();~BeverageFactory();virtual Product* CreateProduct();private:};class WineryFactory :public Factory{public:WineryFactory();~WineryFactory();virtual Product* CreateProduct();private:};
//Product.h#pragma once class Product{public:virtual ~Product() = 0;protected:Product();private:};class BeverageProduct :public Product{public:BeverageProduct();~BeverageProduct();private:};class WineryProduct:public Product{public:WineryProduct ();~WineryProduct ();private:};
//Factory.cpp#include "stdafx.h"#include "Factory.h"#include "Product.h"Factory::Factory(){}Factory::~Factory(){}Product* BeverageFactory::CreateProduct(){returnnewBeverageProduct();}BeverageFactory::BeverageFactory(){printf("建起了饮料厂\n");}BeverageFactory::~BeverageFactory(){}Product* WineryFactory::CreateProduct(){returnnewWineryProduct();}WineryFactory::WineryFactory(){printf("建起了酒厂\n");}WineryFactory::~WineryFactory(){}
//Product.cpp#include "stdafx.h"#include "Product.h"Product::Product(){}Product::~Product(){}BeverageProduct::BeverageProduct(){printf("生产出了饮料\n");}BeverageProduct::~BeverageProduct(){}WineryProduct::WineryProduct(){printf("生产出了茅台酒\n");}WineryProduct ::~WineryProduct(){}
//main.cpp#include "stdafx.h"#include "Factory.h"#include "Product.h"int _tmain(int argc, _TCHAR* argv[]){Factory * fac1 = new BeverageFactory;Factory * fac2 = new WineryFactory;fac1->CreateProduct();fac2->CreateProduct();return 0;}
0 0
- 设计模式------工厂模式
- 设计模式------工厂模式
- 设计模式 [ 工厂模式 ]
- 设计模式--工厂模式
- 设计模式-工厂模式
- 设计模式--工厂模式
- 设计模式 工厂模式
- 设计模式-工厂模式
- 设计模式 -- 工厂模式
- 设计模式-工厂模式
- 设计模式----工厂模式
- 设计模式---工厂模式
- 设计模式-工厂模式
- 设计模式--工厂模式
- 设计模式---工厂模式
- 设计模式-工厂模式
- 设计模式--工厂模式
- 设计模式 - 工厂模式
- N!
- eclipse快捷键
- DELPHI SHA1加密函数
- 最小公倍数(水)
- 【D3.V3.js数据可视化系列教程】--(二)最简单的开始:添加元素
- 设计模式-工厂模式
- android自动生成.apk文件
- 有关可变形部件模型(Deformable Part Model)的一些说明
- 冬日透出暖意
- servlet工作流程
- ListView的嵌套,ExpandableListActivity和SimpleExpandableListAdapter
- poj 1159 Palindrome(最长公共子序列 + 滚动数组)
- 解决Python代码编码问题 SyntaxError: Non-UTF-8 code starting with '\xc1'
- 感谢自己拥有的一切