10.2 The Call Stack
As you step in and out of
Figure 10-12. The call stack
In this case, if you double-click on the second line in the Call Stack window, the debugger will show you the line in Run( ) that called the Time constructor, as shown in Figure 10-13.
Figure 10-13. Tracing the call stack
Chapter 11. Inheritance and Polymorphism
In Chapter 8, you learned how to create new types by declaring classes, and in Chapter 3, you saw a discussion of the principle object relationships of association, aggregation, and specialization. This chapter focuses on specialization , which is implemented in VB.NET through inheritance . This chapter also explains how instances of more specialized classes can be treated as if they were instances of more general classes, a process known as polymorphism . This chapter ends with a consideration of not inheritable classes , which cannot be specialized, and a discussion of the root of all classes, the Object class.
11.1 Specialization and Generalization
Classes and their instances (objects) do not exist in a
The specialization and generalization relationships are both reciprocal and hierarchical. They are reciprocal because specialization is the obverse side of the generalization coin. Thus, Dog and Cat specialize Mammal, and Mammal generalizes from Dog and Cat.
These relationships are hierarchical because they create a relationship tree, with specialized types branching off from more generalized types. As you move up the hierarchy you achieve greater generalization . You move up toward Mammal to generalize that Dogs and Cats and Horses all bear live young. As you move down the hierarchy, you specialize. Thus, the Cat specializes Mammal in having claws (a characteristic) and purring (a behavior).
Similarly, when you say that ListBox and Button
The Unified Modeling Language (UML) is a standardized "language" for describing an object-oriented system. In the UML, classes are represented as boxes. The
In the UML, you model specialization relationships as shown in Figure 11-1. Note that the arrow points from the more specialized class up to the more general class. In the figure, the more specialized Button and ListBox classes point up to the more general Window class.
Figure 11-1. An is-a relationship
It is not uncommon for two classes share functionality. When this occurs, you can factor out these commonalities into a shared base class, which is more general than the more specialized classes. This provides you with greater reuse of common code, and with code that is easier to maintain.
For example, suppose you started out creating a series of objects as
Figure 11-2. Objects deriving from Window
After working with RadioButtons, CheckBoxes, and Command
Figure 11-3. Factoring a Button class
The UML diagram in Figure 11-3 depicts the relationship among the
This is not the only, or even