12.7. Restrict Who Can Extend Your Classes and Override Class Members

Problem

You need to control what code can extend your classes through inheritance and which class members a derived class can override.

Solution

Use declarative security statements to apply the SecurityAction.InheritanceDemand to the declarations of the classes and members that you need to protect.

How It Works

Language modifiers such as NotOverridable, NotInheritable, Public, Private, and Overridable give you a level of control over the ability of classes to inherit from your class and override its members. However, these modifiers are inflexible, providing no selectivity in restricting which code can extend a class or override its members. For example, you might want to ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.