Tuesday, April 04, 2006

Are UML Aggregation and Composition Good Concepts?

Yesterday a work collegue made the remark that the notions of aggregation and composition were not very clear. I was a bit surprised at first. But I actually almost always use just associations relations, sometimes composition, I was not sure anymore about the difference between aggregation and association and the one between composition and aggregation. I had to look up in a book to remember what it was all about.

The French book we looked at was really bad. In the end we did not understand fully the differences except a notion of "stronger coupling", some kind of "asymetry"!?! The difference between aggregation and composition was more explicit since in a composition, the "child" can only have one parent.

The UML Distilled book is much more explicit and I recommend that book to anybody doing UML:
  • Aggregation is strictly meaningless ; as a result, I recommend that you ignore it in your own diagrams .If you see it in other people's diagrams, you'll need to dig deeper to find out what they mean by it . Different authors and teams use it for very different purposes.
  • Composition is a good way of showing properties that own by value, properties to value objects (page 73), or properties that have a strong and somewhat exclusive ownership of particular other components.

Bertrand Meyer prefers to describe relationships using only two concepts, client and heir, basically UML association and specialization and therefore avoids the distinction between aggregation and composition and association:
  • B is a client of A if every object of type B may contain information about one or more objects of type A.
  • B is an heir of A if B denotes a specialized version of A.
He then uses "class invariants" to specify the nature of the client relationship.

2 comments :

  1. In Meyer's world, association and composition are still separate concepts, determined by whether an entity is "expanded" or not.

    There is also a different graphical notation involved for expanded entities. In formal BON the double-line ends with a curly-brace sort of thing instead of an arrowhead, whereas Meyer apparently prefers to keep the arrowhead and draw a line segment across the double-line near the arrowhead.

    ReplyDelete
  2. Thanks, the link you provide is quite good. I did not know about the BON method.
    You are right about expanded entities. It's interesting that in the page you link to, he qualifies an expanded entity as "aggregate", whereas in the book he describes it as "composite".

    ReplyDelete