Qualified Association vs Association Class in UML – Differences and Choices

class-diagramuml

In UML 2.0, there are two ways of representing an association between classes which I can't seem to distinguish between.

First of all, there is the qualified association, represented as such:
qualified association

You also have an association class, represented as such:
association class

I would say that in the case of a qualified association, it is assumed that class 2 holds a reference to an indexed collection of class 1 objects, so it can access a reference to an object of class 1 by its qualifier in the collection.

In the case of an association class, it is usually said that the association class is the association. I would assume in practical terms that at least one of the associated classes has a reference to the association class, which in turn has a reference to both the classes.

I'd love to hear a more educated and insightful perspective on this.

Best Answer

Both diagrams express different things:

  • the qualified association expresses more accurately a complex association. The qualifier has a value semantic: it is made of one or several properties that allow to select the relevant association instances.

    Everything told about the qualified association is true but only if taking into account the qualifier. For example a one to one qualified association could be a one to many association without considering the qualifier.

    The qualifier is only about specifying an association. It does not imply that other propertied could also belong to the the association.

  • the association-class expresses that an association is complex and that it could have additional properties that describes its instances. There is a reference semantic, because there are properties behind that association that belong to neither of the associated classes.

Applying this to your example:

  • In practice, for your simple example, you could use either your association class or a qualified association where the Employee is qualified with a period:dateRange to be associated to 0..1 Company.
  • Your association class diagram is inaccurate since without qualification, an Employee could have had many Company, so that it should be a multiplicity of * on the side of the Company;
  • If your association-class would have more properties than just the period, the qualified association would no longer fully represent your domain.

For the last case, take for example jobTitle : it would depend on period but neither belongs to Employee (an employee can have several job titles), nor to the Company (since there are many job titles in a company), nor to the qualifier (since it does not qualify/subdivide further the association):

  • the association-class would appropriately represent the domain as we know it.
  • If you would insist on the qualified association, you’d need to introduce an additional class to express the same: the Employee qualified with period would be associated with a JobAssignement class, which would contain all the infos that you would otherwise put in the association class. The job assignment class would be associated with the company (many to one).
Related Topic