Search code examples
umlassociationsaggregationclass-diagram

Not understanding the difference between relationships UML


Here I have this class diagram:

enter image description here

Here are the things that I don't understand:

  1. Why is Order - OrderDetail an aggregation? Shouldn't it just be an association, since it will have a List<OrderDetail> like:
public Order{
    public DateTime date;
    public Status status;
    public List<OrderDetail> orderDetails;
}
  1. Why is OrderDetail - Item a dependency? Shouldn't it be association since it has a reference to that Item class?

Reference for the diagram: http://sslabmcs12.weebly.com/resources1.html


Solution

    1. Yes, a simple association would be the right choice. Anyhow, this is a shared aggregation which has no defined semantics. See p. 110 of UML 2.5:

    Indicates that the Property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.

    So you best ask the diagram author about his intentions.

    1. It's not a dependency but an association. A dependency would be rendered with a dashed line. The navigability (the arrow right which made you belief it's a dependency) however is of minor use. It indicates that OrderDetail can see Item but not vice versa. A fact that could better be expressed by using role names only at one side. E.g. placing item only on the right hand side and nothing to the left.

    What can we learn? UML is about communication!