Prototype是创建型模式,通过copy原有的对象创建新的对象。
运行时创建对象
代码示例:
class Base
{
public:
virtual Base*clone() = 0;
};
class Derived : public Base
{
public:
virtual Base *clone()
{return new Derived(*this);}
};
Prototype是创建型模式,通过copy原有的对象创建新的对象。
运行时创建对象
代码示例:
class Base
{
public:
virtual Base*clone() = 0;
};
class Derived : public Base
{
public:
virtual Base *clone()
{return new Derived(*this);}
};