1.Factory模式两个最重要的功能

(1)定义创建对象的接口,封装了对象的创建。

(2)使得具体化类的工作延迟到了子类中。

2.Factory模式结构示意图

3.实现

 #ifndef _PRODUCT_H_
#define _PRODUCT_H_ class Product
{
public:
virtual ~Product() = ;
protected:
Product();
private:
}; class ConcreteProduct:public Product
{
public:
~ConcreteProduct();
ConcreteProduct();
protected:
private:
}; #endif

Product.h

 #include "Product.h"
#include <iostream>
using namespace std; Product::Product()
{ }
Product::~Product()
{ } ConcreteProduct::ConcreteProduct()
{
cout<<"ConcreteProduct..."<<endl;
}
ConcreteProduct::~ConcreteProduct()
{ }

Product.cpp

 #ifndef _FACTORY_H_
#define _FACTORY_H_ class Product; class Factory
{
public:
virtual ~Factory() = ;
virtual Product* CreateProduct() = ;
protected:
Factory();
private:
}; class ConcreteFactory:public Factory
{
public:
~ConcreteFactory();
ConcreteFactory();
Product* CreateProduct();
protected:
private:
};
#endif

Factory.h

 #include "Factory.h"
#include "Product.h" #include <iostream>
using namespace std; Factory::Factory()
{ }
Factory::~Factory()
{ }
ConcreteFactory::ConcreteFactory()
{
cout<<"ConcreteFactory....."<<endl;
}
ConcreteFactory::~ConcreteFactory()
{ }
Product* ConcreteFactory::CreateProduct()
{
return new ConcreteProduct();
}

Factory.cpp

最新文章

  1. Linux Shell中单引号、双引号、反引号的区别【转载】
  2. 文件和目录:access函数
  3. HDU 2082 母函数模板题
  4. 3----lua的数据转换及运算符
  5. NSBundle UIImageView &amp;UIButton
  6. Linux基本命令(7)文件阅读的命令
  7. 慎用preg_replace危险的/e修饰符(一句话后门常用)
  8. SpringMVC文件上传与下载
  9. C和指针 读书笔记
  10. $(function(){})的执行过程分析
  11. 腾讯优图及知脸(ZKface)人脸比对接口测试(python)
  12. PHP递归遍历指定文件夹内的文件
  13. Tomcat——目录结构
  14. PyGame实现情人节表白利器
  15. 用EventEmitter收发消息
  16. 使用Spring+MySql实现读写分离(三)主从复制
  17. es6的模块化--AMD/CMD/commonJS/ES6
  18. 【转】java 读取 excel 2003 或 excel 2007
  19. Kivy 中文教程 实例入门 简易画板 (Simple Paint App):0. 项目简介 &amp; 成果展示
  20. 页面常见布局以及实现方法--flex

热门文章

  1. 推荐!手把手教你使用Git(转)
  2. jquery小技巧:使用jquery.confirm和PNotify实现弹出提示和消息提示
  3. 遇到的cannot find module &#39;xxx&#39; 问题
  4. BZOJ——2134: 单选错位
  5. 洛谷—— P2895 [USACO08FEB]流星雨Meteor Shower
  6. linux下kill某个应用
  7. Maven设置代理
  8. windows10 安装 mysql 5.6 教程
  9. U-net图像分割
  10. MBR结构解析与fdisk的bash实现