Shallow copy and Deep copy (in prototype patterns)

By Ashish Khandelwal, April 5, 2010

There are two types of cloning:

  • Shallow cloning: In shallow copy only that object is cloned, any objects containing in that object is not cloned. For instance consider we have a customer ‘ClsCustomer’ class and we have an address ‘ClsAddress’ class aggregated inside the customer class. The cloning will be done only for customer class ‘ClsCustomer’ but not the ‘ClsAddress’ class.
  • Deep cloning:   The cloning function will be 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.

Summery, 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.

VN:F [1.7.2_963]
Rating: 0.0/5 (0 votes cast)

Leave a Reply