Search code examples
umlclass-diagram

I don't understand association class - UML class diagram


enter image description here

I don't yet completely seem to understand how association class works, why the role class attributes can't just be inside the person class?

as example:

Person

  • name
  • position
  • description

Solution

  • why the role class attributes can't just be inside the person class?

    notice the multiplicity 1..*, if you move position and description into Person you have to manage a collection of them and to associate each to the corresponding Company.

    [from your remark]

    For a given Person the position and description depends on each associated Compagny, so it is not possible to have the fields you propose except if position and description are both a collection, and to have a way/rule to know which entry in position and description correspond to the right Compagny.

    Moving also these information in Person you remove the symmetry, it is also possible to move these information in Compagny, with the same remarks as for Person

    An association class is both a class and a relation, when you implement it in a language like C++ or Java etc of course that concept does not exist, so one way is as you propose to move the fields in one of the two classes, or to create a third class having the expected fields more one to a Person and one to Company.

    The advantage of the third class is to have all the associated information grouped having the equivalent of :

    enter image description here

    As example an object diagram can be :

    enter image description here

    Without the third class you need to know how to associate all the separated information, for instance having all in Person using three vectors to memorize the company and position and description you may use the same index value for all, but this is less clear and when you add/remove a Company for a Person you have to update all these vectors.