您的位置:首页 > 其它

Prototype

2015-09-18 11:28 423 查看
Prototype 模式也正是提供了自我复制的功能,就是说新对象的创建可以通过已有对象进行创建。Prototype 模式提供了一个通过已存在对象进行新对象创建的接口(Clone)



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

};

//ConcretePrototype
class ConcretePrototype:public:Prototype{
public:
ConcretePrototype();
ConcretePrototype(const ConretePrototype &cp);
~ConcretePrototype();
Prototype *Clone() const{

return new ConcretePrototype(*this);
}

};


int main(void){

Prototype *p = new ConretePrototype();
Prototype *p1 = p->Clone();
return 0;
return 0;


}

“`
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: