Are the "Prototype pattern" and the "Virtual constructor" the same patterns?

136 views Asked by At

Does the Virtual constructor - implementing virtual function clone():

class X {
public:
     virtual X* clone() {
         return new X(*this);
     }
};

mean the same concept as the Prototype design pattern?

1

There are 1 answers

0
πάντα ῥεῖ On BEST ANSWER

... mean the same concept as the Prototype design pattern?

No, it doesn't. The cloneable interface is only part of the implementation of the Prototype Design Pattern.

The point of Prototype is to have a Factory to hold instances of prototypical instances, and knows which to use as cloning source to create new instances.