Tuesday, April 13, 2010

What is the advantage of "sealed" keyword in real-world of software development?

3 comments:

Jasmine said...

The keyword "sealed" is applied to methods and classes to prevent overriding and inheritance. A method declared as sealed cannot be overriden in a derived class.
A class that is declared as sealed cannot be a base class(i.e. a class cannot inherit from a sealed class).

All methods in sealed class are sealed implicitly.

A sealed class is a class that does not allow inheritance. Some application designs need to allow only the creation of new instances but prohibit inheritance.In these situations, the class should be declared as sealed.

Advantages of sealed class is it restrict the third party vendor for developing new software by inheriting from our logic.
for example, third party vendors can use Microsoft's .Net dll files and inherit the classes to create a new software.So in this case to protect the classes microsoft declares them as sealed.

Ekta said...

Sealed class is a solution when we want to prevent other classes from inheriting from a class i.e. sealed classes are classes that can't be derived from.
One of the advantage to create sealed class is security reasons. By Inheritance we expose internals of base class to some extent. So if we make a class sealed there is no way that derive class can corrupt its functionality. Also, we might not always want to let someone use our logic and sell it in his name, so by making it sealed we are res assured that no other can inherit out of our .dll to create its own software.

Isha said...

sealed is the c# keyword used at the class level.
This keyword helps class to stop deriving from this class and make this class a final class in its hierarchy.