Is method hiding ever a good idea

前端 未结 8 1843
死守一世寂寞
死守一世寂寞 2020-12-01 09:29

In C# the new modifier can be used to hide a base class method without overriding the base class method.

I\'ve never encountered a situation where hidin

8条回答
  •  星月不相逢
    2020-12-01 09:55

    The most common example I can think of here is things like DbCommand vs SqlCommand; the concrete types (SqlCommand etc) generally do a lot of method hiding to make the return types of properties / methods display the correct implementation type. This is because the related objects themselves have additional (implementation-specific) features, and the caller doesn't want to have to cast every time they call do anything.

提交回复
热议问题