Book contents
- Frontmatter
- Contents
- Preface
- Chapter 1 An Overview of the Visual Basic.NET Language
- Chapter 2 An Overview of Object-Oriented Programming
- Chapter 3 Structures
- Chapter 4 Classes
- Chapter 5 Access Modifiers
- Chapter 6 Abstract Classes and Interfaces
- Chapter 7 Implementing the IEnumerable and IComparable Interfaces
- Chapter 8 Designing and Implementing Exception Classes
- Chapter 9 Design Patterns and Refactoring
- Chapter 10 Object Internals: Reflection and Attributes
- Chapter 11 Object Persistence: Serialization
- Chapter 12 Building a Windows Application
- Chapter 13 Database Programming Using ADO.NET
- References
- Index
Chapter 6 - Abstract Classes and Interfaces
Published online by Cambridge University Press: 06 July 2010
- Frontmatter
- Contents
- Preface
- Chapter 1 An Overview of the Visual Basic.NET Language
- Chapter 2 An Overview of Object-Oriented Programming
- Chapter 3 Structures
- Chapter 4 Classes
- Chapter 5 Access Modifiers
- Chapter 6 Abstract Classes and Interfaces
- Chapter 7 Implementing the IEnumerable and IComparable Interfaces
- Chapter 8 Designing and Implementing Exception Classes
- Chapter 9 Design Patterns and Refactoring
- Chapter 10 Object Internals: Reflection and Attributes
- Chapter 11 Object Persistence: Serialization
- Chapter 12 Building a Windows Application
- Chapter 13 Database Programming Using ADO.NET
- References
- Index
Summary
ABSTRACT CLASSES
As you write more and more complex programs, you will find situations where you want to define classes that are so abstract that you will not want users to implement them directly. Instead, you will want to derive classes from these abstract classes that define more specific data and behavior. Abstract classes are implemented in VB.NET using the MustInherit keyword.
A simple example that beautifully illustrates the concept of abstract classes is food. When you go to a restaurant, you don't order just food. You order some type of food, such as steak, or a salad, or apple pie. Each of these is a specific instance of food, sharing some characteristics with the others, while obviously also differing from the others in substantial ways. Abstract classes let us define a high-level abstract object, such as food, that we can then use as a base class for many different derived classes. Because we would never want to instantiate the abstract class, we mark it abstract (MustInherit) so that it is clear the class is to be used as a base class only.
Creating Abstract Classes
To designate a class as an abstract class in VB.NET, we use the MustInherit keyword. Once a class is defined this way, we can only use the class as a base class for other derived classes.
Within an abstract class, we can declare the usual private data members, constructor methods, property methods, and so on.
- Type
- Chapter
- Information
- Object-Oriented Programming with Visual Basic.NET , pp. 158 - 178Publisher: Cambridge University PressPrint publication year: 2004