设计模式 - Prototype

意图:提供一个通过拷贝已存在对象进行新对象创建的接口。

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

class ConcretePrototype: public Prototype
{
public:
    ConcretePrototype(const string& str)
    {
        this->content = str;
    }
    ConcretePrototype(const ConcretePrototype& cp)
    {
        this->content = cp.content;
    }
    ~ConcretePrototype()
    {}
    Prototype* Clone()
    {
        return new ConcretePrototype(*this);
    }

private:
    string content;
};

 

posted @ 2013-05-04 21:34  Leung文  阅读(103)  评论(0编辑  收藏  举报