Inheritance

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.

Image

Figure 10.2. UML diagram of the Dog hierarchy.

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).

Image

Figure 10.3. UML diagram of the expanded Dog hierarchy.

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).

Image

Figure 10.4. UML diagram of the Canine hierarchy.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.110.131