Sealed classes
In VB, there is no direct equivalent keyword to sealed, which exists in some other programming languages, such as C#. In C#, the sealed
keyword is used to prevent a class from being inherited (that is, it cannot serve as a base class). The sealed concept is important if the programmer has code that should never be specialized. An example could be an authorization class that validates a user and you do not want changes to the authorization method. However, in VB, all classes are inheritable by default, meaning that any class can be used as a base class unless it is specifically designed as an abstract class (using the MustInherit
keyword, as explained in the previous section). To prevent a class from being inherited in VB, you can use the NotInheritable
keyword when defining the class. The NotInheritable
keyword is the equivalent of the sealed
keyword in C#.
Here’s an example of a NotInheritable
class in VB:
NotInheritable Public Class Singleton ...