Abstract Classes
Every subclass of Window
should implement its own DrawWindow
methodâbut nothing requires that it do so. To require subclasses to implement a method of their base, you need to designate that method as abstract
.
An abstract method has no implementation. An abstract method creates a method name and signature that must be implemented in all derived classes. Furthermore, making one or more methods of any class abstract has the side effect of making the entire class abstract.
Abstract classes establish a base for derived classes, but it is not legal to instantiate an object of an abstract class. Once you declare a method to be abstract, you prohibit the creation of any instances of that class.
NotInheritable Class
The opposite side of the design coin from abstract is NotInheritable
. Although an abstract class is intended to be derived-from and to provide a template for its subclasses to follow, a NotInheritable
class does not allow classes to derive from it at all. The NotInheritable
keyword placed before the class declaration precludes derivation. Classes are most often marked NotInheritable
to prevent accidental inheritance.
Get Programming Visual Basic 2005 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.