汕头网站搭建,软件开发服务费,温州网站优化定制,有内涵的公司名原型模式
原型模式就是就是对对象的克隆。有一些私有变量外界难以访问#xff0c;而原型模式可以做到对原型一比一的复刻。
其关键代码为下面的clone方法。此方法将本对象进行复制传递出去。
class ConcretePrototype1 : public Prototype{
public:ConcretePrototype1(stri…原型模式
原型模式就是就是对对象的克隆。有一些私有变量外界难以访问而原型模式可以做到对原型一比一的复刻。
其关键代码为下面的clone方法。此方法将本对象进行复制传递出去。
class ConcretePrototype1 : public Prototype{
public:ConcretePrototype1(string prototype_name, float concrete_prototype_field):Prototype(prototype_name), concrete_prototype_field1(concrete_prototype_field){}Prototype* Clone() { return new ConcretePrototype1(*this); }void printFeild(){ std::cout FEILD:\t concrete_prototype_field1 std::endl; }
private:float concrete_prototype_field1;
};
参考
C设计模式(10)——原型模式_c原型模式-CSDN博客