2

I am learning how to draw a UML class diagram and after reading a few tutorials, I am still confused about the appropriate usages of Association type (The clear diamond and black diamond). I understand their usages but I haven't got a very concrete understanding on when to use them and when not to.

For example in the sample class diagram below, I would have thought that if Customer does not exist, the Order will be gone too but an association diamond was not being used.

Hope someone can provide me with more explaination/examples on the usages of association types.

Thanks.

Sample ordering class diagram

  • There are hundreds of UML examples/tutorials online... just sayin'... – Radu Murzea Apr 21 '13 at 14:40
2

An association links one class to another to indicate a relation between them. For example, you have an association between Customer and Order which (with no further information) indicates that:

  1. A customer can have an order or maybe several orders,

  2. An order can belong to a customer or maybe shared by several customers.

The diagram in your question gives an additional info: there is one and only one customer by order, and zero or more orders by customer, so the rules become:

  1. A customer have zero or more orders,

  2. An order belongs to one and one only customer.

While aggregation is used in the association between Order and OrderDetail, it's not used in the association between Customer and Order. This is done to indicate the life cycle dependency. If an instance of the Order is destroyed, all instances of OrderDetail inside it would be destroyed too; on the other hand, the instances of Order are independent of the life cycle of the Customer instance, thus no aggregation here.

This doesn't mean that an order can exist without a customer: the 1 ↔ 0..* association explicitly forbids the orders which have no customers. The difference between a 1 ↔ 0..* association and the aggregation really happens on life cycle level.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.