Instance Cloning


Sometimes I got confused myself how to copy an instance to another identical instance.  I found an interface called “ICloneable Interface”. When in use this interface will create a new method called “Clone”. In this method I need to write code to create a new instance and then copy the content of every property into the new instance. The process of cloning gave me another question mark, why should I use “ICloneable Interface” while I could copy the instance without using the interface. Could I remove the “ICloneable Interface”?

Luckily I found this thread in one of StackOverflow’s forum. Matt Hamilton, that referred Brad Adam’s article, suggested that we should not use “ICloneable Interface” anymore, because it only done a shallow-copy.  He recommended that we should create our own “Clone” method to do the cloning.

References:

Leave a comment