Friday, December 03, 2004

Abstract and Sealed Pattern in .NET

The CLR doesn't allow types to be marked as both Abstract and Sealed. You can get around this by doing the following.

public sealed class AbstractAndSealed
{
private AbstractAndSealed()
{
}
}

In this way, no instances of the type can be created. I call it the abstract and sealed pattern. You can use this pattern when you are designing your own type that contains only static members. Examples are System.Console and System.Math.

I learned the abstract and sealed pattern from Jeffrey Richter's book

Applied Microsoft .NET Framework Programming

0 Comments:

Post a Comment

<< Home