博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Factory 模式
阅读量:4683 次
发布时间:2019-06-09

本文共 1555 字,大约阅读时间需要 5 分钟。

1 Factory.h 2 #ifndef _FACTORY_H_ 3 #define _FACTORY_H_ 4  5 class Product ; 6  7 class Factory 8 { 9 public:10     virtual ~Factory() = 0 ;11 12     virtual  Product* CreatProduct() = 0;13 14 protected:15     Factory();16 private:17 };18 19 class ConcreteFactory : public Factory 20 {21 public:22     ~ConcreteFactory();23     ConcreteFactory();24     Product* CreatProduct();25 protected:26 private:27 };28 29 #endif
1 Factory.cpp 2 #include "Factory.h" 3 #include "Product.h" 4  5 #include 
6 using namespace std; 7 8 Factory::Factory() 9 {10 11 }12 13 Factory::~Factory()14 {15 16 }17 18 ConcreteFactory::ConcreteFactory()19 {20 cout<<"ConcreteFactory....."<
1 Product.h 2 #ifndef  _PRODUCT_H_ 3 #define  _PRODUCT_H_ 4 class Product 5 { 6 public: 7     virtual ~Product()=0; 8  9 protected:10     Product();11 private:12 };13 14 15 class ConcreteProduct : public Product16 {17 public:18     virtual ~ConcreteProduct();19     ConcreteProduct();20 protected:21 private:22 };23 24 25 #endif
1 Product.cpp 2 #include "Product.h" 3 #include 
4 using namespace std; 5 6 Product::Product() 7 { 8 9 }10 11 Product::~Product()12 {13 14 }15 16 ConcreteProduct::ConcreteProduct()17 {18 cout<<"ConcreteProduct"<
1 main.cpp 2 #include "Factory.h" 3 #include "Product.h" 4  5 #include 
6 using namespace std; 7 8 int main() 9 {10 Factory *fac = new ConcreteFactory() ;11 12 Product *p = fac->CreatProduct();13 getchar();14 return 0 ;15 }

 

转载于:https://www.cnblogs.com/csxcode/p/3687325.html

你可能感兴趣的文章
js复制对象
查看>>
编写Linux中sh文件执行时出现莫名字符的问题
查看>>
数据库自定义函数
查看>>
Object.assign()是浅拷贝
查看>>
简单FTP服务器搭建
查看>>
关于Sublime Text 3搭建Java环境的补充
查看>>
【FFMPEG】Ubuntu上安装FFMPEG
查看>>
【QT开发】信号转发器QSignalMapper的使用
查看>>
关于VS2010工程各种路径注意事项汇总
查看>>
java中volatile不能保证线程安全
查看>>
Oracle左连接、右连接、全外连接以及(+)号用法
查看>>
追加内容到指定的行
查看>>
Centos7下安装Redis
查看>>
Codeforces Round #369 (Div. 2) C. Coloring Trees DP
查看>>
Android Preference 实现长按监听 long-clickable
查看>>
03 django1.0.2 默认管理配置
查看>>
mysql 中 unix_timestamp和from_unixtime函数
查看>>
Java Web项目BlogAutoGenerator编写日志1
查看>>
简单数论(一)
查看>>
Populating Next Right Pointers in Each Node
查看>>