01.01.2015 Views

UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

122<br />

Saturday Afternoon<br />

Fruit<br />

Apple Watermelon Orange<br />

RedDelicious<br />

GrannySmith<br />

Figure 11-5 Modeling generalization<br />

<strong>To</strong> express the same thing in words, I might say, “A ‘Red Delicious’ is a type of apple, and<br />

an apple is a type of fruit.” For this reason, you sometimes hear generalization called the<br />

“is a” relationship (that is, every red delicious object “is an” apple object and every apple<br />

object “is a” fruit object).<br />

This unique relationship between classes in a generalization raises an interesting problem.<br />

In Session 9, I described the concept of visibility. Visibility determines which other objects<br />

can see the attribute or operation. Normally, attributes are set to private so that only objects<br />

of the same class may see them. But what would happen to the RedDelicious class in Figure<br />

11-5 if the attributes of the Apple class were set as private RedDelicious would not have<br />

access to them so inheritance is in essence short-circuited. Another visibility, called protected<br />

visibility, is defined to handle just this situation. The protected visibility allows only objects<br />

of the same class or subclasses to see the element.<br />

Note<br />

There are variations in the implementation of the protected visibility<br />

between programming languages. Be sure to check the language manual for<br />

the correct interpretation.<br />

Elements of generalization<br />

Because the generalization (also called an inheritance) relationship is not a form of association,<br />

there is no need for multiplicity, roles, and constraints. These elements are simply<br />

irrelevant.<br />

<strong>To</strong> draw a generalization relationship, we first need to define superclass, subclass,<br />

abstract class, concrete class, and discriminator. A superclass is a class that contains some<br />

combination of attributes, operations, and associations that are common to two or more<br />

types of objects that share the same purpose. Fruit and Apple are examples of superclasses.<br />

The term superclass reflects the concept of superset. The superset or superclass in this case<br />

contains the traits that are common to every object in the set.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!