d0001
d0001

Reputation: 2190

Why are association, aggregation and composition used the way they are used in this example?

I understand the differences between the three( or at least I think I do). I know there are many other similar questions with definitions like this one.

I was looking an example from gliffy.com and I am strugiling to understand why some releationship were used they way they were used. I guess what I'm really struggling with is understanding when to use association.

Some of the questions I have are:

  1. Why is Customer-Order and Customer-Credit Card an association an not aggregation like Customer-Address?
  2. Why is Order-ItemOrder not composition given that ItemOrder would not exist without an Order?
  3. Why is ItemOrder-Item not aggregation?

Online Golf store UML

Upvotes: 0

Views: 1939

Answers (2)

www.admiraalit.nl
www.admiraalit.nl

Reputation: 6099

In order to answer these questions, it is important to know why this class diagram is drawn. Only the author knows, but maybe it is just a demonstration of the capabilities of gliffy? Otherwise, maybe the classes in this model correspond to classes in source code, written in an object-oriented language like Java or C# and that the diagram is aimed to give insight in the relationships among these classes.

  1. Why is Customer-Order and Customer-Credit Card an association and not aggregation like Customer-Address?

    Apparently, the author does not regard these relationships to be 'part-of' relationships. Maybe Customer does not have any reference to Orders or CreditCards in the source code. Maybe Address information belongs to the responsibility of class Customer, but Order and Credit Card information do not.

  2. Why is Order-ItemOrder not composition given that ItemOrder would not exist without an Order?

    Maybe the author only uses a subset of UML and does not use composition by convention. Maybe the author thinks the difference between aggregation and composition is not important to convey for the purpose of this diagram.

  3. Why is ItemOrder-Item not aggregation?

    Apparently, the author does not regard this relationship to be a part-of relationship. Maybe the author has reserved the aggregation type of relationship to represent one particular programming language construct, which is not used in this case in the source code. Maybe the author has the opinion that an interface can never be aggregated in another class.

By the way, the aggregation between ItemOrder and ShoppingCart is clearly wrong. I think the diamond should be on the other side of the relationship.

Upvotes: 3

qwerty_so
qwerty_so

Reputation: 36333

Simply forget about shared/composite aggregation. It does have a low semantics and just leads to futile discussions whether it's needed and where it's used right or wrong. Just use (and interpret) the association and multiplicity.

The (almost) only place where you could use aggregations in a meaningful way is in DB foreign key (force delete) and memory (free unused) management.

Upvotes: -1

Related Questions