This post originated from an RSS feed registered with .NET Buzz
by Brad Wilson.
Original Post: My Favorite Use of Sealed
Feed Title: The .NET Guy
Feed URL: /error.aspx?aspxerrorpath=/dotnetguy/Rss.aspx
Feed Description: A personal blog about technology in general, .NET in specific, and when all else fails, the real world.
Ingo and Clemens are talking about sealed classes today. I'm not going to talk about that. :)
Instead, I'll share the coolest thing I learned about the sealed keyword. It works on virtual methods just like sealing classes. For instance, if you have a class:
public class Foo
{
protected virtual void Baz() { ... }
}
You can override and seal in a derived class:
public class Bar : Foo
{
protected override sealed void Baz() { ... }
}
This lets you end the chain of virtual override. Classes that derive from Bar are no longer allowed to override the Baz() method.