To understand how inheritance is represented, consider the Dog
example presented in Chapter 7, “Mastering Inheritance and Composition.” In this example, the class GoldenRetriever
inherits from the class Dog
, as shown in Figure 10.2. This relationship is represented in UML by a line with an arrowhead pointing in the direction of the parent or superclass.
The notation is straightforward, and when the line with the arrowhead is encountered, an inheritance relationship is indicated.
Because Java is primarily used for the code examples in this book, we do not have to worry about multiple inheritance. The same goes for .NET and Objective-C. C++ does implement multiple inheritance.
However, several subclasses can inherit from the same superclass. Again, we can use the Dog
example from Chapter 7 (see Figure 10.3).
This example illustrates two concepts when modeling an inheritance tree. First, a superclass can have more than one subclass. Second, the inheritance tree can extend for more than one level. The example in Figure 10.3 shows three levels. We could add further levels by adding specific types of retrievers, or even by adding a higher level by creating a Canine
class (see Figure 10.4).
18.223.110.131