Sealant
A .NET source code analysis package, developed by humans, that reports a compiler warning whenever a class is not sealed, static, abstract, or marked unsealed, and includes code fixes that add sealed or an unsealed comment.
Install
No framework information available.
README
Sealant
Sealant is a .NET source code analysis package, developed by humans, that reports a compiler warning whenever a class is not sealed, static, abstract, or marked unsealed.
Platform support: any project built with .NET SDK 6.0 or later, for any target framework.
Quick start
- Install Sealant.
If your IDE supports .NET source code analysis, it shows a warning for each class that is not sealed, static, abstract, or marked unsealed. Build your project to see the same warnings from the command line. The package only provides .NET source code analysis and code fixes, and adds no runtime dependency to your project.
Why
Inheritance is sometimes the right approach, but far less often than its prevalence suggests. Alan Kay, who coined the term object-oriented programming, put it this way:
Unfortunately, inheritance—though an incredibly powerful technique—has turned out to be very difficult for novices (and even professionals) to deal with.
— Alan Kay, The Early History of Smalltalk (1993)
Inheritance is powerful, but it is also a commitment. Once someone derives from a type, changing that type becomes harder, and closing the type later is a breaking change.
Jamie Zawinski's old joke about regular expressions applies with one substitution:
Some people, when confronted with a problem, think "I know, I'll use inheritance." Now they have two problems, and a base class they can never change.
— after Jamie Zawinski
Tutorials do not help: the standard example is still an Animal, a Dog, and a Cat—a hierarchy that exists nowhere else.
The default should make closing a type the easy path, not the afterthought.
Some languages already work this way. Kotlin classes are final by default, and open makes them inheritable. Swift requires open to subclass a class outside its defining module. C# takes the opposite default: its classes are inheritable by default. Unless the author remembers to choose sealed, static, or abstract, a class invites subclasses it was never designed for.
Jeffrey Richter, in CLR via C#, argues that the default is the wrong way round:
When defining a new type, compilers should make the class sealed by default so that the class cannot be used as a base class. ... Obviously, it is too late now, but I think that today's compilers have chosen the wrong default and it would be nice if it could change with future compilers.
— Jeffrey Richter, CLR via C#
Sealant removes inheritance by default, making it deliberate, not accidental.
Rules
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.