UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory UML Weekend Crash Course™ - To Parent Directory

crnarupa.singidunum.ac.rs
from crnarupa.singidunum.ac.rs More from this publisher
01.01.2015 Views

SESSION 11 The Class Diagram: Aggregation and Generalization Session Checklist ✔ Explaining the concepts of aggregation and composition ✔ Illustrating the use of the notation for aggregation and composition ✔ Explaining the concepts of generalization and inheritance ✔ Illustrating the use of generalization In Session 10, you learned about associations. An association describes a set of rules regarding how objects may be related to one another. But associations can be a bit more restrictive. In this session, I describe two common subtypes of association, called aggregation and composition. Then I explain how you can refactor your design using generalization (inheritance). Modeling Aggregation and Composition Figure 11-1 outlines the relationships among the concepts of association, aggregation, and composition. Later in this session, I explain the contents of this graphic more fully. But right now I want to make two points as clear and strong as possible: Every aggregation relationship is a type of association. So every aggregation relationship has all the properties of an association relationship, plus some rules of its own. Every composition relationship is a form of aggregation. So every composition relationship has all the properties of an aggregation, plus some rules of its own.

118 Saturday Afternoon Association Objects are aware of one another so they can work together Aggregation 1. Protects the integrity of the configuration 2. Functions as a single unit 3. Control through one object – propagation downward Composition Each part may only be a member of one aggregate object Figure 11-1 composition The relationship between association, aggregation, and Elements of aggregation Aggregation is a special type of association used to indicate that the participating objects are not just independent objects that know about each other. Instead, they are assembled or configured together to create a new, more complex object. For example, a number of different parts are assembled to create a car, a boat, or a plane. You could even create a logical assembly like a team where the parts are not physically connected to one another but they still operate as a unit. To model aggregation on a Class diagram: 1. Draw an association (a line) between the class that represents the member and the class that represents the assembly or aggregation. In Figure 11-2, that would mean a line between the Team class and the Player class. 2. Draw a diamond on the end of the association that is attached to the assembly or aggregate class. In Figure 11-2, the diamond is next to the Team class that represents a group of players. 3. Assign the appropriate multiplicities to each end of the association, and add any roles and/or constraints that may be needed to define the rules for the relationship. Figure 11-2 shows that a Player may be a member of no more than one Team, but a Player does not have to be on a Team all the time (0..1). The Team is always comprised of exactly nine Players (9..9 or just 9). A Player is considered a member (role name) of a Team. Every Player is constrained by the fact that she must have a current contract in order to be a member of a Team. {must have a current contract} Team member Player Figure 11-2 0..1 9..9 How to represent an aggregation relationship in the UML

SESSION<br />

11<br />

The Class Diagram: Aggregation<br />

and Generalization<br />

Session Checklist<br />

✔ Explaining the concepts of aggregation and composition<br />

✔ Illustrating the use of the notation for aggregation and composition<br />

✔ Explaining the concepts of generalization and inheritance<br />

✔ Illustrating the use of generalization<br />

In Session 10, you learned about associations. An association describes a set of rules<br />

regarding how objects may be related to one another. But associations can be a bit<br />

more restrictive. In this session, I describe two common subtypes of association, called<br />

aggregation and composition. Then I explain how you can refactor your design using generalization<br />

(inheritance).<br />

Modeling Aggregation and Composition<br />

Figure 11-1 outlines the relationships among the concepts of association, aggregation, and<br />

composition.<br />

Later in this session, I explain the contents of this graphic more fully. But right now I<br />

want to make two points as clear and strong as possible:<br />

Every aggregation relationship is a type of association. So every aggregation relationship<br />

has all the properties of an association relationship, plus some rules of its own.<br />

Every composition relationship is a form of aggregation. So every composition<br />

relationship has all the properties of an aggregation, plus some rules of its own.

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

Saved successfully!

Ooh no, something went wrong!