5

Is it possible to have an association without explicitly indicating the reference attributes in the participating classes in the UML class diagram? For example, consider this example :

enter image description here

We can see there is an association between the customer and order classes, however, from the attributes compartment of both classes, I cant find any reference attributes ? or these attributes are implicitly indicated through the association line and there is no need to indicate them in the attributes compartments ?

2 Answers 2

6

So long as the reference isn't to a basic data type, not only is it possible, it's common practice.

Redundantly showing both is also possible. But I've never seen a rule requiring it.

It's also common practice to show some associations only with attributes (no line), even to full fledged classes, that are simply being omitted from this particular diagram. Rather than always including everything, sometimes your point is best made on a single piece of paper.

2
  • I agree with this answer and offer: an association symbol is warranted, an opened or black diamond, or dependency arrow. This specifies the relationship's nature and allows better design analysis, including use case coverage; for example an order existing without an existing customer. Attribute reference per se does not convey such design intent.
    – radarbob
    Mar 3 at 23:38
  • @radarbob indeed, the design intent is best communicated using the graphic relationship and the role name. You may also add the dot notation to soecify the real nature of relationships ;-)
    – Christophe
    Mar 4 at 17:05
3

The proper UML way is to name the reference with a role name at the association end instead of in the attribute section:

enter image description here

The role has also visibility (public, private...) exactly as do attributes.

Adding at the same time the association, and the attribute that implements it, is redundant. Indeed, an attribute and an association with an "owned end" are almost equivalent in UML. Showing both could even be ambiguous since they could also mean multiple associations with the same class.

An even better way would be to use the more modern UML dot notation.

Note that UML is agnostic regarding the implementation of associations. They do not have to be implemented via attributes at all (they could for example be implemented via distinct objects that implement the association, e.g. dictionaries and so on).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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