首页 > 其他 > 详细

Prototype Pattern(原型模式)

时间:2015-05-06 17:42:03      阅读:142      评论:0      收藏:0      [点我收藏+]
/*Prototype.h*/
#ifndef PROTOTYPE_H
#define PROTOTYPE_H

class Prototype
{
public:
    virtual ~Prototype();
    virtual Prototype *Clone() const=0;
protected:
    Prototype();
private:
};

class ConcretePrototype:public Prototype
{
public:
    ConcretePrototype();
    ConcretePrototype(const ConcretePrototype &cp);
    ~ConcretePrototype();
    Prototype *Clone() const;
protected:
private:
};
#endif
/*Prototype.cpp*/
#include "Prototype.h"
#include <iostream>

Prototype::Prototype()
{
}

Prototype::~Prototype()
{
}

ConcretePrototype::ConcretePrototype()
{
}

ConcretePrototype::~ConcretePrototype()
{
}

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

Prototype *ConcretePrototype::Clone() const
{
    return new ConcretePrototype(*this);
}
/*main.cpp*/
#include "Prototype.h"
#include <iostream>

int main()
{
    Prototype *p=new ConcretePrototype();
    Prototype *p1=p->Clone();
    return 0;
}

Prototype Pattern(原型模式)

原文:http://blog.csdn.net/tlzhatao/article/details/45537993

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!