Deciding between Aggregation and Composition


You might find it difficult to decide between modeling a relationship as an association, an aggregation, or a composition. Here are a few clues to look for when you’re modeling relationships:

  • If you hear words like “part of,” “contains,” or “owns,” then you probably have an aggregation relationship.

  • If the life-cycle of the parts are bound up within the life-cycle of the whole, then you have a composite.

  • If the parts are shared, then it’s an aggregation.

  • If the parts are not shared, then you may have composition.

Aggregations (and composition) also have two other identifying properties: they’re not symmetric but they are transitive. Hang on, these are fancy terms for a couple of simple ideas. An association is symmetric if it is the same thing in both directions. Think of the relationship between a generic report and one of its columns. Although it’s true that the column is part of the generic report, it’s not true that the generic report is also part of the column. (Seems obvious, doesn’t it?) When you’re deciding about whether you have a part-of relationship, ask the symmetry question. The transitive property is a fancy way of saying: If A is a part of B, and B is a part of C, then A is also a part of C.

Here’s a down-to-earth way to say that again: If a filament (A) is a part of a light bulb (B), and a light bulb (B) is part of a lamp (C), then the filament (A) is also part of the lamp (C). If you can apply the transitive property, then chances are you have an aggregation.

Table 5-1 summarizes these criteria to help you decide whether you have an aggregation, composition, or association.

Table 5-1: Aggregation Versus Composition: Clues

Decision Result

Criteria

Aggregation or Composition

Part-of, contains, owns words are used to describe relationship between two classes

Aggregation or Composition

No symmetry

Aggregation or Composition

Transitivity among parts

Composition

Parts are not shared

Composition

Multiplicity of the whole is 1 or 0..1

Aggregation

Parts may be shared

Aggregation

Multiplicity of the whole may be larger than 1

Association

Relationship does not fit the other criteria




UML 2 for Dummies
UML 2 For Dummies
ISBN: 0764526146
EAN: 2147483647
Year: 2006
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net