When should you call base.Method() in overridden method, and how to mark this when you write code in team?

前端 未结 3 1095
轻奢々
轻奢々 2020-12-15 04:32

When using some framework/api, sometimes it\'s pretty unclear if you must call base.Method if you override it, for example you can be pretty sure that you should call base.M

3条回答
  •  渐次进展
    2020-12-15 05:10

    Nowadays I don't think that consumers of a class that override a method should ever need to call base.Method(). The code should be written in such way that it cannot be broken.

    public class MyBase
    {
        private void FooInternal()
        {
            DoRequiredStuff();
            Foo();
        }
        public virtual void Foo() {}
    }
    

提交回复
热议问题