Can an association class have a subclass?

Viewed 127

So I have an association class C that is an association between classes A and B. Class D is a subclass of class C as it contains data from class C. Is it possible? and can it be represented as a diagram? If yes then how can I associate class D with class A and B too since class D is also an association class to classes A and B?

2 Answers

Let's take an example:

  • A = Person
  • B = Team
  • C = Membership
  • D = Leadership

cd

You have two questions:

  1. Is it allowed to have the generalization between C and D, i.e. between Membership and Leadership?
  2. Is it allowed to have an association between A and D, i.e. between Person and Leadership, like association 'assists' in the diagram?

Ad 1: The UML 2.5 specification, section 11.5.3, last sentence, reads:

An AssociationClass cannot be a generalization of an Association or a Class.

That is why people say the answer is 'No' and I think they are right. However, one might argue that Leadership inherits all properties of Membership, even the fact that it is an assocation class. I don't see any problem with this interpretation. It prevents the need for modeling an extra association, just to let Leadership be an assocation class by itself. So, I would say it is allowed.

Ad 2: Yes, it is allowed to have an association between a normal class and an assocation class, like association 'assists' in my example.

If, as you say, Class D is an AssociationClass as well, it is possible.

However, a simple Class cannot be a subclass of an AssociationClass.

Where is the problem representing this in a diagram? Simply show the Generalization between the two AssociationClasses. Please note, since Associations are Classifiers, even simple Associations can have a Generalization. enter image description here One problem is, that the AssociationEnds of D will be separate Properties. You want them to be the same Properties as the ends of C. The only way to achieve this, as far as I can see, is to make them subsets, and derive them.

Edit: To completely avoid the problem, you could simply use a normal class and two associations: enter image description here Since the UML-taskforce has unfortunately removed the only reason for the existence of AssociationClasses, there is no disadvantage in doing so.

Related