UML Weekend Crash Course⢠- To Parent Directory
UML Weekend Crash Course⢠- To Parent Directory UML Weekend Crash Course⢠- To Parent Directory
Session 11—The Class Diagram: Aggregation and Generalization 123 A subclass is a class that contains some combination of attributes, operations, and associations that are unique to a type of object that is partially defined by a superclass. In Figure 11-5, Apple, Watermelon, Orange, RedDelicious and GrannySmith are all examples of subclasses. Note that a class may be both a superclass and a subclass. The term subclass reflects the concept of subset. The subset, or subclass, contains a unique set of properties for only certain objects within the set. The GrannySmith class in Figure 11-5 would only contain the properties that are unique to GrannySmith apples. A GrannySmith object would get the rest of the information about the properties it shares with all apples from the Apple superclass, and all the properties it has in common with all fruits from the Fruit superclass. In other words, it actually takes three classes to generate a single object representing a GrannySmith apple. An abstract class is a class that cannot create objects (cannot be instantiated). Any superclass that defines at least one operation that does not have a method is said to be abstract, or lacking a complete definition. Only a superclass can be abstract. A concrete class is a class that has a method for every operation, so it can create objects. The methods may be defined in the class or inherited from a superclass. All classes at the bottom of a generalization hierarchy must be concrete. Any superclass may be concrete. A discriminator is an attribute or rule that describes how I choose to identify the set of subclasses for a superclass. If I wanted to organize the information about types of cars, I could discriminate based on price range, manufacturer, engine size, fuel type, usage, or any number of other criteria. The discriminator I choose depends on the problem I am trying to solve. In Figure 11-6, I use a very common practice. I identify a set of predefined types (that is, type of fruit and varieties within types). Other times I might use a property of the objects themselves like size, price range, capacity, or age. Fruit Discriminator Fruit Type Apple Watermelon Orange Discriminator RedDelicious Fruit Variety GrannySmith Figure 11-6 Modeling generalization with discriminators The composition of a class reveals the possible discriminating properties. Classes define properties of objects such as attributes, operations, and association. These are the first three possible discriminating properties. If objects of the class share the same attributes,
124 Saturday Afternoon like age and address, they might be in the same subgroup. However, objects might have the same attribute (like age), but the values allowed for age in some of the objects are different from those allowed in others. For example, every Person has an age value assigned. However, minors would have age values less than 21 (in some states) and adults would have ages greater than 20. The same concept applies to operations. Objects might have the same operation, that is, the same interface, like “accelerate.” But different objects might implement that interface in very different ways. A car accelerates very differently from a rocket. Even different cars accelerate using different combinations of parts and fuels. In summary, there are at least five objective criteria I can use to discriminate between objects within the same class (superclass): Attribute type Attribute values allowed Operation (interface) Method (implementation) Associations Tip Proper use of the discriminator facilitates the use of design patterns such as abstract factory and state. There are actually two ways to draw a generalization. Figure 11-5 showed separate lines from each subclass to its superclass. Figure 11-6 merged the lines from all the subclasses of a superclass. In either form, draw a triangle at the superclass end of the generalization line (pointing to the superclass). (Note that you draw a triangle, not an arrow.) Connect the other end of the generalization to the subclass. Add the discriminator on the generalization line in simple text. An illustration: How to model generalization Building a generalization hierarchy can work in two directions, from the most general class down to the most specialized classes (specialization), and from the most specialized classes to the most generalized class (generalization). The following example builds from general concept down to specifics, using the class Dog. I need to keep track of various breeds in a dog obedience school in order to understand and anticipate their unique training requirements. Step 1: Draw the starting superclass, as in Figure 11-7. It is a class like any other class. The only thing that makes it a superclass is the fact that I plan to break it down.
- Page 95 and 96: 72 Saturday Morning You reply that
- Page 97 and 98: 74 Saturday Morning Writing a Use C
- Page 99 and 100: 76 Saturday Morning Use Case dialog
- Page 101 and 102: 78 Saturday Morning Table 7-7 The F
- Page 104 and 105: SESSION 8 Identifying the Use Case
- Page 106 and 107: Session 8—Identifying the Use Cas
- Page 108 and 109: Session 8—Identifying the Use Cas
- Page 110 and 111: Session 8—Identifying the Use Cas
- Page 112 and 113: Session 8—Identifying the Use Cas
- Page 114: Session 8—Identifying the Use Cas
- Page 117 and 118: 94 Saturday Morning The Class diagr
- Page 119 and 120: 96 Saturday Morning Attribute visib
- Page 121 and 122: 98 Saturday Morning In a modeling t
- Page 123 and 124: 100 Saturday Morning Table 9-2 Cont
- Page 125 and 126: 102 Saturday Morning Operation comp
- Page 128 and 129: SESSION 10 The Class Diagram: Assoc
- Page 130 and 131: Session 10—The Class Diagram: Ass
- Page 132 and 133: Session 10—The Class Diagram: Ass
- Page 134 and 135: Session 10—The Class Diagram: Ass
- Page 136 and 137: Session 10—The Class Diagram: Ass
- Page 138 and 139: Part II — Saturday Morning Part R
- Page 140 and 141: SESSION 11 The Class Diagram: Aggre
- Page 142 and 143: Session 11—The Class Diagram: Agg
- Page 144 and 145: Session 11—The Class Diagram: Agg
- Page 148 and 149: Session 11—The Class Diagram: Agg
- Page 150: Session 11—The Class Diagram: Agg
- Page 153 and 154: 130 Saturday Afternoon or not. Each
- Page 155 and 156: 132 Saturday Afternoon 5. “Any it
- Page 157 and 158: 134 Saturday Afternoon designed to
- Page 159 and 160: 136 Saturday Afternoon Table 12-3 T
- Page 161 and 162: 138 Saturday Afternoon REVIEW The C
- Page 163 and 164: 140 Saturday Afternoon Introducing
- Page 165 and 166: 142 Saturday Afternoon Table 13-1 C
- Page 167 and 168: 144 Saturday Afternoon 28: VendorPr
- Page 169 and 170: 146 Saturday Afternoon 0..* VendorP
- Page 172 and 173: SESSION 14 Modeling the Functional
- Page 174 and 175: Session 14—Modeling the Functiona
- Page 176 and 177: Session 14—Modeling the Functiona
- Page 178: Session 14—Modeling the Functiona
- Page 181 and 182: 158 Saturday Afternoon Table 15-1 T
- Page 183 and 184: 160 Saturday Afternoon Figure 15-1
- Page 185 and 186: 162 Saturday Afternoon More product
- Page 187 and 188: 164 Saturday Afternoon start (merge
- Page 190 and 191: SESSION 16 Modeling the Dynamic Vie
- Page 192 and 193: Session 16—Modeling the Dynamic V
- Page 194 and 195: Session 16—Modeling the Dynamic V
Session 11—The Class Diagram: Aggregation and Generalization 123<br />
A subclass is a class that contains some combination of attributes, operations, and associations<br />
that are unique to a type of object that is partially defined by a superclass. In<br />
Figure 11-5, Apple, Watermelon, Orange, RedDelicious and GrannySmith are all examples<br />
of subclasses. Note that a class may be both a superclass and a subclass.<br />
The term subclass reflects the concept of subset. The subset, or subclass, contains a<br />
unique set of properties for only certain objects within the set. The GrannySmith class in<br />
Figure 11-5 would only contain the properties that are unique to GrannySmith apples. A<br />
GrannySmith object would get the rest of the information about the properties it shares<br />
with all apples from the Apple superclass, and all the properties it has in common with all<br />
fruits from the Fruit superclass. In other words, it actually takes three classes to generate a<br />
single object representing a GrannySmith apple.<br />
An abstract class is a class that cannot create objects (cannot be instantiated). Any<br />
superclass that defines at least one operation that does not have a method is said to be<br />
abstract, or lacking a complete definition. Only a superclass can be abstract.<br />
A concrete class is a class that has a method for every operation, so it can create objects.<br />
The methods may be defined in the class or inherited from a superclass. All classes at the<br />
bottom of a generalization hierarchy must be concrete. Any superclass may be concrete.<br />
A discriminator is an attribute or rule that describes how I choose to identify the set of<br />
subclasses for a superclass. If I wanted to organize the information about types of cars, I<br />
could discriminate based on price range, manufacturer, engine size, fuel type, usage, or any<br />
number of other criteria. The discriminator I choose depends on the problem I am trying to<br />
solve. In Figure 11-6, I use a very common practice. I identify a set of predefined types<br />
(that is, type of fruit and varieties within types). Other times I might use a property of<br />
the objects themselves like size, price range, capacity, or age.<br />
Fruit<br />
Discriminator<br />
Fruit Type<br />
Apple Watermelon Orange<br />
Discriminator<br />
RedDelicious<br />
Fruit Variety<br />
GrannySmith<br />
Figure 11-6 Modeling generalization with discriminators<br />
The composition of a class reveals the possible discriminating properties. Classes define<br />
properties of objects such as attributes, operations, and association. These are the first<br />
three possible discriminating properties. If objects of the class share the same attributes,