Alex Rivera | Logout

Why is MemberwiseClone defined in System.Object protected?

Asked 2010-07-17T16:42:16.933
15

I'm wondering why MemberwiseClone is defined as protected. This means that only derived types can access it. What is the problem if it was defined as public?

Edit
Report

1 Answer

5
  • A lot of things don't make sense to be cloned; anything that talks to an unmanaged handle, for example
  • Most objects do not need a clone facility
  • Deep-copying something properly is really hard if you go outside of a few simple cases
  • In many cases, there are better metaphors than blind clones
  • Manually adding a clone facility to your types that need it is trivially easy

To me, then, it is a no-brainer that this should not be added to the public API by default.

answered 2013-03-15T11:41:10.333

Your Answer