tags:

views:

370

answers:

2

It is unclear to me from the MSDN documentation if I should provide a deep or a shallow clone when implementing ICloneable. What is the preferred option?

+1  A: 

Clones are deep by default, thats the naming convention and copy constructors can be shallow if they want, for performance reasons.

Edit: This naming convention goes beyond boundaries, its the same for .Net, Java, C++, Javascript, etc... the actual source is beyond my knowledge but its part of the standard Object Oriented lexicon, just like objects, and classes. Thus MSDN doesn't specify implementation because its a given by the word itself (of course lots of newcomers to OO languages don't know this, and they SHOULD specify it, but then again their documentation is quite frugal anyways)

Robert Gould
Could you provide more detail, whose naming convention?
Jim Burger
That isn't correct. MSDN docs don't say HOW Clone should be implemented.
MagicKat
+12  A: 

Short answer: Yes.

Long Answer: Don't use ICloneable. That is because .Clone isn't defined as being a shallow or a deep clone. You should implement your own IClone interface, and describe how the clone should work.

MagicKat