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

Prototype Pattern(原型模式)

时间:2015-05-06 17:43:10      阅读:124      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!