UML 2 For Dummies


You categorize classes in many different ways. A person class could be categorized by age, income, job role, or location. You use inheritance as a way to categorize your subclasses. If a subclass can inherit from one superclass, why not from two or more superclasses? Well, it can; UML allows you to show such multiple inheritance. For example, the MovieFilm class is an instance of RecordedMedia and of PhotoMedia. It should have all the attributes and operations of both superclasses, as illustrated in Figure 6-10. You show multiple inheritance in UML by connecting the subclass to each of its superclasses with a generalization relationship.

Figure 6-10: Inheritance from classes.

Ah, but does the use of multiple inheritance make our programs richer? Sometimes. There are both advantages and disadvantages to using multiple inheritance. First, the advantages:

Now for the disadvantages:

 Tip   During analysis, we use inheritance hierarchies to capture the way our users think about their world. During design, however, we try to stay away from multiple inheritance. In the long run, its disadvantages outweigh its advantages.


Категории