Search code examples
javac#oopumlobject-oriented-analysis

Using Association Class or just Association arrow


I am currently studying OOP and UML together, there is confusion regarding the use of association class or just the plain association. Let say a Company hires Person, as far as I know there are two ways to associate them, the first way is just a regular type of association(I think this is aggregation) like this. Regular associationenter image description here

The second way is to use an associative class, kind of like the one the ER diagram, but the Company class no longer has the responsibility to hire any Person.

enter image description here

My questions are:

  1. Which one is correct? (It seems like the second one makes more sense, but the first one isn't wrong either)
  2. If the first way is not wrong, but then wouldn't Company knows too much about Person?
  3. In what situations do I consider using association class over regular association?

Solution

  • Your association is not an aggregation, an aggregation has an empty diamond (<>), so it is a simple association.

    None of the association ends has a name even when navigable, so why are you using an association rather than may be a dependency if you do not want property ? Of course if it is not an association you cannot have an association-class.

    In the class Company we can see the attribute Employees, are you sure you do not want :

    enter image description here

    or

    enter image description here

    You named the association as the operation (hire), of course you can but an association just represent a semantic relationship, so hire does not represent the operation.

    As rightly said by @Axel Scheithauer in his answer in case of an association-class the name of the class and the name of the association are common properties and must not be duplicated so cannot be different, from formal/2017-12-05 § 11.5.3.2 Association Classes page 200 :

    Both Association and Class are Classifiers and hence have a set of common properties, like being able to have Features, having a name, etc. These properties are multiply inherited from the same construct (Classifier), and are not duplicated. Therefore, an AssociationClass has only one name, and has the set of Features that are defined for Classes and Associations.

    About to use an association or an association-class it is a choice.

    If you want to know the date the company hired an employee and the employee salary (when hired / current) for sure an association-class is a good choice clearly showing what you want.

    But you can also have Onboarding as a third class out of an association class and having association between the 3 classes :

    enter image description here

    and you can also have date and salary as attributes of Person supposing a person is necessary an employee :

    enter image description here

    else you can have the class Employee inheriting Person and having these additional attributes :

    enter image description here

    You have Java and C# as tag, none of these language support association-class, so even you use an association-class in UML when implementing it in Java / C# you will probably use one of the two other solutions.


    Because there is no bidirectional navigability a company knows his employees but an employee does not know the company or companies where he/her works, do you really want that ?