In UML is it correct to have an association class with a composition or aggregation relationship

class-diagramcompositionuml

An example of an association class is given here:

http://pic.dhe.ibm.com/infocenter/rsarthlp/v9/index.jsp?topic=%2Fcom.ibm.xtools.modeler.doc%2Ftopics%2Fcassnclss.html

Composition and Aggregation are also types of Associations, just with more defined semantics to what the association consists of.

Can association classes also be part of a relationship by Composition or Aggregation? That is, in the case where there is a many-to-many relationship between two entities, with some additional attributes on the relationship. Or would it be more correct to model that as two separate one-to-many relationships onto a middle entity that hold the additional attributes?

Best Answer

The UML concept of an "association class" is questionable (in terms of its semantics and usability) and I'd recommend not using it, but always explicitly express the class representing the association, connecting it to the participating object classes with many-to-one associations.

The questionable usability of the "association class" concept is illustrated by the flawed IBM example Student-Enrollment-Course referenced in your question. In this example, contrary to what is stated, Enrollment cannot be an "association class" if Course represents the general concept of a course offering (without semester information), because an "association class" admits of only one link between the same participant objects (a student and a course), while the domain semantics requires that a student can repeatedly take a course, implying more than one enrollment link between the same student and the same course.

Related Topic