Why aren't classes sealed by default?

前端 未结 9 1742
天命终不由人
天命终不由人 2020-12-05 22:59

I was just wondering, since the sealed keyword\'s existence indicates that it\'s the class author\'s decision as to whether other classes are allowed to inh

9条回答
  •  北海茫月
    2020-12-05 23:34

    In my opinion there should be no default syntax, that way you always write explicitly what you want. This forces the coder to understand/think more.

    If you want a class to be inheritable then you write

    public extensible class MyClass
    

    otherwise

    public sealed class MyClass
    

    BTW I think the same should go with access modifiers, disallow default access modifiers.

提交回复
热议问题