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

【设计模式】Prototype Pattern

时间:2015-06-14 19:59:31      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

main.cpp

#include "Prototype.h"
#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
    
    Prototype *p = new ConcreatePrototype();

    Prototype *p1 = p->Clone();

    return 0;
}

Prototype.h

#ifndef _PROTOTYPE_H
#define _PROTOTYPE_H

class Prototype {
public :
    virtual ~Prototype();

    virtual Prototype *Clone() const = 0;
protected :
    Prototype();
};

class ConcreatePrototype :public Prototype {
public :
    ConcreatePrototype();

    ConcreatePrototype(const ConcreatePrototype &cp);

    ~ConcreatePrototype();

    Prototype *Clone() const;
};

#endif

Prototype.cpp

#include "Prototype.h"
#include <iostream>
using namespace std;

Prototype::Prototype() {}

Prototype::~Prototype() {}

Prototype *Prototype::Clone() const {
    return 0;
}

ConcreatePrototype::ConcreatePrototype() {}

ConcreatePrototype::~ConcreatePrototype() {}

ConcreatePrototype::ConcreatePrototype(const ConcreatePrototype &cp) {
    cout << "ConcreatePrototype..." << endl;
}

Prototype *ConcreatePrototype::Clone() const {
    return new ConcreatePrototype(*this);
}

 

【设计模式】Prototype Pattern

标签:

原文地址:http://www.cnblogs.com/Susake/p/4575453.html

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