Search code examples
umlassociationsaggregationcompositionclass-diagram

How should aggregation and association be thought of


Let's say we have a supermarket chain and a number of supermarkets belong to it.

If the chain ceases to exist the supermarkets will have to shut down. This could be implemented in UML using a composition relationship. On what side of the association should the filled-in diamond be located?

  • Should it be like Chain----<.>supermarket ? Or chain<.>-----supermarket) ?
  • Should I think of it as the supermarkets belong to the chain or the chain has supermarkets?

Solution

  • In UML, you put the composition diamond next to the class that composes another. In your example, An individual of type Chain composes [1] several individuals of type Supermarket, so the black diamond goes on the Chain end of the association.


    [1] Some people pronounce this "Chain has Supermarkets", which is indistinguishable from a different sense of the word "has", as in "Chain has name".