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.

Session 11—The Class Diagram: Aggregation and Generalization 119<br />

What makes aggregation unique More importantly, what makes aggregation beneficial<br />

Aggregation describes a group of objects in a way that changes how you interact with them.<br />

The concept is aimed at protecting the integrity of a configuration of objects in two specific<br />

ways.<br />

First, aggregation defines a single point of control in the object that represents the<br />

assembly. This ensures that no matter what others might want to do to the members of the<br />

assembly, the control object has the final word on whether the actions are allowed. This<br />

assignment of control may be at many levels within the aggregation hierarchy. For example,<br />

an engine might be the controller of its parts, but the car is the controller of the engine.<br />

Second, when an instruction is given that might effect the entire collection of objects,<br />

the control object dictates how the members will respond. So for all intentions, the assembly<br />

appears to function like a single object. When I push the gas pedal, telling the car I<br />

want to accelerate, the entire car assembly (with its thousands of parts) accelerates, not<br />

just the gas pedal.<br />

Elements of composition<br />

Composition is used for aggregations where the life span of the part depends on the life<br />

span of the aggregate. The aggregate has control over the creation and destruction of the<br />

part. In other words, the member object cannot exist apart from the aggregation. Draw this<br />

stronger form of aggregation simply by making the aggregation diamond solid (black).<br />

In Figure 11-3, the team example uses aggregation, the hollow diamond. Players are<br />

assembled into a team. But if the Team is disbanded, the players live on (depending of<br />

course on how well they performed). The Book example uses composition, the solid diamond.<br />

A Book is composed of Chapters. The Chapters would not continue to exist elsewhere<br />

on their own. They would cease to exist along with the Book.<br />

Team<br />

Aggregation<br />

0..1 9..9<br />

Player<br />

Book<br />

Composition<br />

1..1 1..*<br />

Chapter<br />

Figure 11-3 How to represent a composition relationship in the <strong>UML</strong><br />

Note how the multiplicity provides some clues on the distinction between aggregation<br />

and composition. On the Team example in Figure 11-3, each Player may or may not be a<br />

member of a Team (0..1). This tells me that a Player may exist independent from the Team.<br />

The Book example says that a Chapter must be associated with one and only one Book<br />

(1..1). This tells me that a Chapter cannot exist independent of the Book, so it must be a<br />

composition relationship.

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

Saved successfully!

Ooh no, something went wrong!