Inadvertently seeing this articleArticleI think the author wrote a vivid image and quickly shared it with you:
Certificate ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
In the software world, these two concepts are no stranger to us, such. net object. for memberwiseclone () and prototype design mode clone, copy is more common, such as copying a piece of text.
Essentially, copy and clone are identical. They all use a mechanism to create a new object. Since the difference is not an essential concept, the difference between them must be reflected in two aspects: one is "how" and the other is the "why" closely related to the external environment ".
In terms of "how:
Copy is to construct a new object based on the attributes of an existing object. This object has all the attributes of the existing object, but does not include the external attributes referenced by this object. For example, when we copy a document, we do not need to copy the citation. Obviously, we do not care about the actual content of the citation.
Clone also constructs a new object based on the attributes of an existing object. Different from copy, the new object generated after clone not only has all attributes of the existing object, but also includes all attributes of the object referenced by the existing object.
From the aspect of "why:
The object generated by copy does not include the attributes of the object referenced by the original object. All newly generated objects lack the ability to express themselves, that is, they can only be in the same context as the referenced object. For example, copy a and reference object B are usually located in the same document.
Because the clone object has the ability to express itself, it and the referenced object do not have to be in the same context. For example, we can use clone to exchange data between two different documents.
In software development, too many concepts often make the software more complex, because in actual development, we only need to adopt one of them, for another concept, we only need to add an adjective to it. For example:
"Shallow copy" = copy; "Deep copy" = clone
" memberwise clone "= copy;" clone "= clone