Tuesday, September 21, 2010

C# Tidbits: Signed, sealed, delivered classes

The “sealed” keyword for classes was new to me (and certainly not part of C++). So, the first time i encountered it (from a year ago) it got me interested. There are a lot of more extensive (and official) discussions but here is my uber-brief summary:

1. abstract
class that you cannot instantiate. the developer intended it to be derived from.
use for: base classes or as interface between classes
2. sealed
class that you cannot derive from, but can be instantiated (cannot be abstract).
this is called a "leaf" class.
use for: prevent anymore derivation (you’re finalizing the class hierarchy).
3. static
class that cannot be derived from, nor can be instantiated (sealed + abstract).
use for: utility classes with only static functions inside.

So, "static" classes in c# are sealed abstract classes.
For the “official” info, you can always Google them. hehe

0 comments:

Post a Comment