views:

411

answers:

3

I've recently spent a good deal of time performing detailed UML designs of various SW components that I have since written. Looking back on what I have recently finished and comparing that to when I first learned UML, I see that I now almost strictly use Aggregation and Composition relationships, and have virtually abandoned "vanilla" non-directed/directed relationships. I still of course use Generalizations and Realizations, but these are distinctly different than those above and are not considered part of this question.

It seems to me that Aggregation/Composition implies the same meaning of "vanilla" associations, and more. Aggregation and Composition naturally imply a direction, and any modern UML program will still allow you to define multiplicity on an Aggregation/Composition relationship and apply a verb to the relationship as well. At that point, I see little purpose to vanilla associations.

I understand some people have difficulty understanding the difference between Aggregation and Composition. Early on, I had a bit of difficult grasping how they differ, and I believe that confusion was part of the reason I used vanilla associations. I'm at the point now where I see little or no use for vanilla associations, and actually dislike seeing them used as I believe they leave some things up for question (particularly a strong or weak lifecycle relationship between two objects). I believe vanilla associations' only practical use is when your understanding of the problem at hand isn't yet developed enough to determine the life cycle difference between aggregation and composition. In such a case it is better to atleast show that the relationship exists and you can then come back and change it appropriately when you have a better understanding of the problem at hand.

Long story short, I believe the vast majority of the time that people use vanilla associations, they could be more accurately described as an aggregation, and sometimes as a composition. Am I terribly wrong in my belief? Am I missing something? Let me hear it!

A: 

Both aggregations and compositions imply that a participant in the relationship "dominates" the other (in compositions the dominance is stronger), while normal associations don't have this implication. Therefore, I use normal associations when both participants have the same importance in the relationship

Jordi Cabot
A: 

On a class diagram, you are thinking of the static relationships between classes. You probably don't really need to think about the behavioural aspects of those relationships on the class diagram, it just muddies the waters and is evidence of over-analysis. (IMHO of course)

chimp
+2  A: 

You have hit on the head when you say, 'vanilla associations' only practical use is when your understanding of the problem at hand isn't yet developed enough to determine the life cycle difference and show that the relationship exists and you can then come back and change it appropriately when you have a better understanding of the problem at hand.

The UML Meta-Model defines Aggregation and Composition as extensions of Association, therefore an Association is an unrefined relationship between domain objects, in the same way that a Domain object is an unrefined Class. I typically use Association at the Domain Modelling stage and refine it into either Composition or Aggregation when I resolve the detailed Class Model.

Martin Spamer
Well explained yet concise answer. Makes sense. Thanks Martin!
James