Inheritance

 <  Day Day Up  >  

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.

Figure 10.2. UML diagram of the Dog hierarchy.

graphics/10fig02.gif

The notation is straightforward, and when the line with the arrowhead is encountered , an inheritance relationship is indicated.

Indicating Interface Inheritance

A dashed line with an arrowhead indicates an interface, which is discussed in the next section.


Because Java is used for the examples in this book, we do not have to worry about 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).

Figure 10.3. UML diagram of the expanded Dog hierarchy.

graphics/10fig03.gif

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

Figure 10.4. UML diagram of the Canine hierarchy.

graphics/10fig04.gif

 <  Day Day Up  >  


Object-Oriented Thought Process
Object-Oriented Thought Process, The (3rd Edition)
ISBN: 0672330164
EAN: 2147483647
Year: 2003
Pages: 164
Authors: Matt Weisfeld

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net