4 ms·
Without sealed classes it's impossible to enforce most interesting invariants. If anything the other way is a mistake.
by Jweb_Guru 5y ago
Without sealed classes it's impossible to enforce most interesting invariants. If anything the other way is a mistake.
- shagie 5y agoReasonable arguments can be made that sealed classes should be the default. From https://news.ycombinator.com/item?id=16952659 https://news.ycombinator.com/item?id=16952659 (and all the related links to that comment and the original article - The Impoliteness of Overriding Methods)
- int_19h 5y agoIMO sealing for classes is unnecessary, so long as methods are opt-in for overriding (e.g. as in C++ or C#, where you need to explicitly say "virtual"). If you can't override anything in a derived class, how can you break invariants?