UML   «Prev  Next»
Lesson 8 Modeling Aggregation and Composition
Objective Define the Notation for specifying aggregation and composition associations.

Modeling Aggregation and Composition:

Aggregation is a special type of association used to indicate that objects are assembled together to create a new object. For example, a number of different parts are assembled to create a car, a boat, or a plane.


Aggregation Composition Modeling
To identify aggregation, use a diamond on the end of the association attached to the aggregate class and attach the other end of the association to the component class. Remember to assign the appropriate multiplicity to each end of the association.
In most cases, the multiplicity at the aggregate end is one, so many people do not bother to set this value.


The UML has a new form of association called composition. Composition is used for aggregations where the life span of the parts depends on the life span of the aggregate. To indicate composition, simply make the diamond black.
Composition is the act of collecting several objects together to create a new one. Composition is usually a good choice when one object is part of another object. We've already seen a first hint of composition in the mechanic example. A car is composed of an engine, transmission, starter, headlights, and windshield, among numerous other parts. The engine, in turn, is composed of pistons, a crank shaft, and valves. In this example, composition is a good way to provide levels of abstraction. The car object can provide the interface required by a driver, while also providing access to its component parts, which offers the deeper level of abstraction suitable for a mechanic. Those component parts can, of course, be further broken down if the mechanic needs more information to diagnose a problem or tune the engine. This is a common introductory example of composition, but it's not overly useful when it comes to designing computer systems. Physical objects are easy to break into component objects. People have been doing this at least since the ancient Greeks originally postulated that atoms were the smallest units of matter (they, of course, didn't have access to particle accelerators). Computer systems are generally less complicated than physical objects, yet identifying the component objects in such systems does not happen as naturally.

Aggregation and composition
In the graphic above, the team example uses aggregation. A team is composed of players. But if the team is disbanded, the players live on. The book example uses composition because a book is composed of chapters. If the book is destroyed, the chapters are destroyed as well.
In the next lesson, you will learn about composition context.
Model Aggregation Composition Associations - Exercise
Click the Exercise link below to model aggregation and composition associations.
Model Aggregation Composition Associations - Exercise

UML Aggregation Composition - Quiz
Now click the Quiz link below to take a short multiple-choice quiz on aggregation and composition.
UML Aggregation Composition - Quiz