1

Let's assume I have 2 classes with association relation.

What is the difference between adding attributes to one of the classes and adding an Association Class with attributes?

I understand that association class describes the association relation, but cannot I use simple class attributes instead?
What are the added values of Association Class?

2
  • Did you mean association? an association class is even more different!
    – Jim L.
    Jan 17, 2016 at 12:13
  • @JimL., I mean association class. Thanks in advance! Jan 17, 2016 at 13:39

2 Answers 2

5

Association and attributes are actually different renderings of the same thing. The difference is more a bit of esoteric nature. An association is visually more exposed than an attribute. So you would use the attribute if it has a more local importance rather than a more system wide in case of an association.

What you should not do is to use both. When using an association and you need to name it then use a role along with the association and do not repeat it as attribute.

An association class (AC) is actually a combination of a class and an association (in UML it inherits from both). This way the pure relation between two classes can have methods and attributes itself. An association class is used if you want to relate two classes with M-N relation. E.g. the AC between Student and Exam describes the results a student has achieved in exams. So you have a Class 1-M AC N-1 Class relation rather than having this information as array attributes inside either of the opposing classes.

As a side note (since you tagged it EA): EA offers a drop down in the roles which is fed from attributes of the class. You should not make use of that. This is some heritage and/or a misinterpretation of the definition. As said: its not wrong, but also not good style.

2
  • Thanks. Can you please extend your answer a little so I can understand the explanation regarding "Association Class"? Jan 17, 2016 at 13:38
  • See my addition. Is that ok?
    – qwerty_so
    Jan 17, 2016 at 14:03
2

You say you already have two classes with an association between them. In that case, there is a huge difference between adding attributes to one of those two classes and changing the association into an association class with its own attributes. They are not at all similar.

  1. Unnamed properties already exist at each end of the association and are typed by their adjacent class. Adding redundant attributes is unnecessary and would be incorrect.
  2. An association class allows you to record additional facts about a link between instances of the other two classes, such as the point in time the link came into existence. Association classes are like associative entities in a database.

I think part of your question is also about when to use an association vs when to use attributes. The UML spec doesn't provide any guidance on this. However, common practice is to use an attribute only for types that have no identity, such as the number "5", the string "Hello", or the combination of "7" with an enumeration literal of "pounds". In UML, these types are called primitives and datatypes. If you want a property typed by one of those, use an attribute; otherwise, use an association with named association ends.

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.