Prototype Patten
Published in
1 min readJun 23, 2019
The goal of the prototype pattern is to make cloning objects (even complex nested objects) trivial.
Key takeaways from the Prototype Pattern
- Delegates the responsibility for copying an object to the class of that object via (the constructor).
- The object.clone() uses this keyword to pass its self its into a constructor to produce a clone
- This pattern makes it easy to copy private fields which any external actor would not be able to access
- The patter is also compatible with cloning an object with a complex inheritance structure by merely delegating the copying of the instance variables to its superclasses via Super()