Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 775
beginpluses Avatar asked Aug 30 '26 10:08

beginpluses


1 Answers

... 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.

like image 191
πάντα ῥεῖ Avatar answered Sep 03 '26 00:09

πάντα ῥεῖ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!