码迷,mamicode.com
首页 > 其他好文 > 详细

Prototype Pattern

时间:2015-07-16 13:24:10      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

prototype 模式结构图:

技术分享

实现:

技术分享
 1 #ifndef _PROTOTYPE_H_
 2 #define _PROTOTYPE_H_
 3 
 4 class Prototype
 5 {
 6 public:
 7     virtual ~Prototype();
 8     virtual Prototype* Clone() const = 0;
 9 
10 protected:
11     Prototype();
12 
13 private:
14 };
15 
16 class ConcretePrototype:public Prototype
17 {
18 public:
19     ConcretePrototype();
20     ConcretePrototype(const ConcretePrototype& cp);
21     ~ConcretePrototype();
22     Prototype* Clone()const;
23 protected:
24 private:
25 };
26 
27 #endif
Prototype.h
技术分享
 1 #include "Prototype.h"
 2 #include <iostream>
 3 using namespace std;
 4 
 5 Prototype::Prototype()
 6 {
 7 
 8 }
 9 Prototype::~Prototype()
10 {
11 
12 }
13 Prototype* Prototype::Clone()const
14 {
15     return 0;
16 }
17 ConcretePrototype::ConcretePrototype()
18 {
19 
20 };
21 ConcretePrototype::~ConcretePrototype()
22 {
23 
24 }
25 ConcretePrototype::ConcretePrototype(const ConcretePrototype& cp)
26 {
27     cout<<"ConcretePrototype copy..."<<endl;
28 }
29 Prototype* ConcretePrototype::Clone()const
30 {
31     return new ConcretePrototype(*this);
32 }
Prototype.cpp

 

Prototype Pattern

标签:

原文地址:http://www.cnblogs.com/programmer-wfq/p/4649189.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!