Defining Classes That Cannot Be Subclassed When a branch of your class hierarchy comes to a point and you want to ensure that no further inheritance occurs, you can define a final class. A final class is a class that has the NotInheritable modifier in the class statement. For example, if we wanted to indicate that no child class can be derived from the SingleEngineLand plane, we could introduce the NotInheritable keyword, revising the class statement as follows : Public NotInheritable Class SingleEngineLand With that done, consumers can no longer subclass SingleEngineLand planes. Using modifiers like NotInheritable or MustInherit is like using access specifiers Public, Private, Protected, or Friend, in that you can elect not to use them. Make everything public and avoid modifiers altogether if you want to, but the end result is code that is less explicit and controlled. Explicit controlled code is more likely to yield manageable, less complex code. |
Team-Fly |
Top |