The prototype pattern
The prototype pattern is used to create new objects by cloning fields from an existing object, or the prototype object. The idea is that some objects are difficult or time-consuming to construct, so it would be useful to make a copy of the object and call it a new one by making small modifications.
As Julia keeps data and logic separate, making copies of objects is really the same as duplicating the content. That sounds easy, but we should not overlook the difference between a shallow copy and a deep copy.
A shallow copy of an object is merely an object with all the fields copied from another object. A deep copy of an object is created by recursively going into the fields of the object and copying their underlying fields ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access