12 August 2005

Sealing a method or a class prevents subclasses from overriding it.

In C# you use the keyword sealed, in Java you use the keyword final. Languages like C# and C++ consider methods sealed by default (you unseal them with the virtual keyword) other languages (such as Java) leave methods unsealed by default.

There is quite a lot of controversy about whether sealing is a good idea. Those with a DirectingAttitude like be very careful about what classes and features are available for overriding and confine extenders to only override things they consider safe. Those with an EnablingAttitude take the view that they cannot predict what extenders may need to do and thus shouldn't deny them the flexibility - extenders can override whatever they like, but they have to take the responsibility to be careful. As in most things I tend to being an enabler.