#830 – The Problem with ICloneable
April 25, 2013 1 Comment
The ICloneable interface in the .NET Framework includes a single Clone method, meant to make a copy of the object it is invoked on, returning the new copy.
The problem with the ICloneable interface is that it gives client code that uses it no information about whether a deep or a shallow copy (or something in between) is going to be done. Given the ambiguity and the fact that the client doesn’t really know what the contents of the cloned object will be, it’s recommended that you don’t implement ICloneable, but rather design your own interface or methods, where you can make the semantics more clear.