0

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.

0

2 Answers 2

3

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).
0

The difference depends on the level of abstraction you are aiming for in your model.

In the first the association is qualified (named) without providing details of what the association is. If the details of the attribute in your class which will hold the association object (or a reference to it) is not important then go for this approach.

In the second you have the ability to model the details of the association. It also allows you to reuse the same association class in other contexts.

Of course there's the third option of having an association is without qualification at all. Clearly this is the case where your model online needs to convey the nature of the association and that it exists, and a name adds no further insight.

2
  • In the case of the qualified association, you can have multiple attributes in the qualification, but I guess it still has a lower level of detail than the association class, so I get what you're saying. Also, it's not reusable, indeed.
    – David Cian
    Jan 28, 2020 at 22:55
  • 1
    @DavidCian you are right, I guess the thrust of my answer is that it is all about the level of detail you want to convey in your model. My approach for modelling has always been to remove detail which does not help the audience (otherwise why show a class diagram when you can just get them to read code ;)). The only exception to this approach is when using UML as a basis for code generation, in this case one has to include all relevant detail otherwise it won't be in the code (unless you only want the code to be used as stubs, not very useful IMHO)
    – hhafez
    Jan 28, 2020 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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