#830 – The Problem with ICloneable

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.

 

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #830 – The Problem with ICloneable

  1. Pingback: Dew Drop – April 26, 2013 (#1,535) | Alvin Ashcraft's Morning Dew

Leave a comment