a specialization of a class, inherits all the attributes and associations of the parent class. Can a specialization not participate in an association of the parent class?
example: an employee and his manager specialization. Can the manager participate in the association that links the employee and the company?
Indeed a specialization inherits the associations of its parent class.
So, if Employee
has an association with Employer
(e.g an employee has 1 employer and an employer has * employees), and if Manager
is a specialization of Employee
, it inherits the same association.
There are ways to change the inherited elements:
The two are visually presented by drawing the association between Manager
and Employer
. In the first case you'd add a {redefines ...}
adornment at the association ends, and in the second case you'd draw a generalization arrow between the two associations (not every tool accepts this, despite it being legit UML). You can find here some examples of specialized associations. And this research paper gives a full overview of this advanced UML feature.
You may wonder: if there is a specialize or redefined association, how does it help? well, just change the multiplicities to 0..0
.
This being said, this looks ugly. And the bad feeling this gives is at the same time a good reminder that it might not be a good idea. Indeed, Liskov Substitution Principle tells us that an element of the specialized type should be possibly used interchangeably for an element of the super type (i.e. whenever you do something with an employee, you could do it with a manager instead). And this design breaks this principle.
More generally, you may well design in UML things which have a bad OOP design, but you should not necessarily do it.