15 thoughts on “XE7 System.Threading – sealed classes?

  1. From the C# docs

    To determine whether to seal a class, method, or property, you should generally consider the following two points:

    – The potential benefits that deriving classes might gain through the ability to customize your class.

    – The potential that deriving classes could modify your classes in such a way that they would no longer work correctly or as expected.

  2. Performance: only if you use it to replace “is” checks with “ClassType=” (has it’s uses, quite corner case)

    Also it can make sense for future proofing, if you know where you want the structure to go, but haven’t had time to implement it yet, and don’t want people to build upon your structures in ways that would prevent those structures to evolve (because people bitch, rightfully, at breaking changes).

  3. Lars Fosdal yes, but the alternative is either bloating the class with some “SomeMethod2” or “SomeMethodEx” once you realize people overrode the “SomeMethod” to do things they should not have, or just abandoning the old structure and starting anew… which is just as annoying 🙂

  4. A few possible motivations for sealing a class come to mind:

    1. If you design an immutable class any programmer that comes after you can write a descendent that ignores that immutability, breaking any assumptions you may have made in your design.

    2. Sealing a class can be a heavy handed way to enforce composition over inheritance.