Reading this article (by Eric Lippert), it has four arguments as to why you should use sealed
, however, I don't understand why we actually need it. Philosophical/aesthetic reasons aside, why do we need to use sealed?
I can see how things like readonly
from C# or const
from C++ actually catch genuine errors. Is there any type of error that sealed
can catch?
An often cited reason for sealing a class is because, it hasn't been to designed to be extended. What does that mean? Why is it important? Are there any real examples of this?
The point on compatibility isn't a reason why we need to seal classes but why it should be default.
The final point again is strange, because sealing your class doesn't prevent someone providing an alternative implementation in a heirachy.
Edit:
If I didn't put enough emphasis, on it already I'm looking for reasons we actually need it. Not the usual, "someone else might write bad code". I understand that plenty of people like using sealed
for design intent, but I'm looking for a practical purpose beyond that.