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.



Blog Directory - OnToplist.com