Aggregation

Aggregation is a specific kind of association that shows a relationship between two classes that play a different role. One of the classes is considered the whole and the other one is considered the part. An aggregation expresses a whole-part relationship. Figure 4-10 shows the UML representation of an aggregation.

Figure 4-10. The UML representation of an aggregation.

Figure 4-10. The UML representation of an aggregation.

The association presented in Figure 4-10 shows the relationship between a soil profile and its soil layers. The association is a one-to-many; meaning that a soil profile is composed of one or more soil layers. The class SoilProflle represents the whole and class SoilLayer represents the part. The open diamond distinguishes the whole class. It is important to note that in an aggregation, the whole does not own the part. Therefore, when the class representing the whole is destroyed, this does not affect the class representing the part. Furthermore, an object representing the part may be used in other aggregations. An aggregation is an association that represents a whole-part relationship in a conceptual way.

As aggregation expresses the whole-part relationship in a very loose manner, many modelers do not see it as useful modeling concept. A relationship expressed by an aggregation can be modeled using a simple association. In this case, the name of the association could express the idea of whole-part relationship. Choosing between an aggregation and a simple association for conceptually expressing the whole-part relationship is a question of taste or modeling habits.

A one-to-many association can implemented in Java as an array. Line 4 in Figure 4-11 shows that the attribute soilLayer is an array that will contain objects of type SoilLayer.

1 package Soil;

0 0

Post a comment