Can you explain shallow copy and deep copy in prototype patterns?

There are two types of cloning for prototype patterns. One is the shallow cloning which you have just read in the first question. In shallow copy only that object is cloned, any objects containing in that object is not cloned. For instance consider the figure ‘Deep cloning in action’ we have a customer class and we have an address class aggregated inside the customer class. ‘MemberWiseClone’ will only clone the customer class ‘ClsCustomer’ but not the ‘ClsAddress’ class. So we added the ‘MemberWiseClone’ function in the address class also. Now when we call the ‘getClone’ function we call the parent cloning function and also the child cloning function, which leads to cloning of the complete object. When the parent objects are cloned with their containing objects it’s called as deep cloning and when only the parent is clones its termed as shallow cloning.

Figure: – Deep cloning in action

Tagged , , . Bookmark the permalink.

One Response to Can you explain shallow copy and deep copy in prototype patterns?

  1. Mliijzuin says:

    Excellent post and also straight to the idea. I am not sure if it is actually the best place to ask nevertheless do you people have any the thing it where to use some professional writers to write great articles? Thanks in advance 🙂

Leave a Reply