Attention: We have retired the ASP.NET Community Blogs. Learn more >

Do not use IClonable

1.1 Implementing ICloneable
The ICloneable interface contains a single Clone method, which is used to create a copy of the current object.

public interface ICloneable {

    object Clone();

}

?      Do not implement ICloneable

There are two general ways to implement ICloneable, either as a deep, or non-deep copy. Deep-copy copies the cloned object and all objects referenced by the object, recursively until all objects in the graph are copied. A non-deep copy (referred to as ‘shallow’ if only the top level references are copied) may do none, or part of a deep copy.

Because the interface contract does not specify the type of clone performed, different classes have different implementations. A consumer cannot rely on ICloneable to let them know whether an object is deep-cloned or not.

public <type> Copy();

?      Do not use ICloneable in public APIs"

[Brad Abrams]

I guess we should mark IClonable as obsolete / depreciated...

2 Comments

Comments have been disabled for this content.