Is using “base” bad practice even though it might be good for readability?

前端 未结 5 1686
野性不改
野性不改 2021-01-11 13:24

I know this is a subjective question, but I\'m always curious about best-practices in coding style. ReSharper 4.5 is giving me a warning for the keyword \"base\" before bas

5条回答
  •  清歌不尽
    2021-01-11 13:44

    I think generally you should use base only when overriding previous functionality.

    Some languages (C# does not) also provide this functionality by calling the function by it's base class name explicitly like this: Foo.common() (called from somewhere in Bar, of course).

    This would allow you to skip upwards in the chain, or pick from multiple implementations -- in the case of multiple-inheritance.

    Regardless, I feel base should be used only when needed to explicitly call your parent's functionality because you are or have overridden that functionality in this class.

提交回复
热议问题