Design Pattern/Notes/Creational
Prototype Pattern
Prototype is a creational design pattern that lets you copy existing objects without making your code dependent on their classes.
Problem
We want to make an exact copy of an object (copy every property). The most intuitive method is to make a new object with constructor or setter methods.
However, if an object has private fields, it's not possible to clone it with the above methods.
Solution
Use an interface containing a single method, clone
.
You can even copy private fields because most programming languages let objects access private fields of other objects that belong to the same class.
Sample Code
Limitation
Reference
How is this guide?