Why Sealed Classes?

Why Sealed Classes?

The main purpose of a sealed class to take away the inheritance feature from the user so they cannot derive a class from a sealed class. One of the best usage of sealed classes is when you have a class with static members. For example, the Pens and Brushes classes of the System.Drawing namespace.

The Pens class represent the pens for standard colors. This class has only static members. For example, Pens.Blue represents a pen with blue color. Similarly, the Brushes class represents standard brushes. The Brushes.Blue represents a brush with blue color.

So when you're designing your application, you may keep in mind that you have sealed classes to seal user's boundaries ;).

By Mahesh Chand @ www.c-sharpcorner.com

Some really nice articles on Sealed Classes and Methods in .NET.

http://www.csharphelp.com/archives/archive158.html
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfsealed.asp
http://www.c-sharpcorner.com/Code/2002/Sept/SealedClasses.asp
http://www.lemanix.com/nick/archive/2005/10/19/3178.aspx

0 comments:

 
Blog Directory - OnToplist.com