Let's suppose that we have a User class that is necessarily associated with a Role, which can be DogLover or CatLover.
We have another abstract class called Animal, which has two implementations, Dog and Cat.
The User has an attribute called pet that will be a Cat or a Dog, depending on the Role chosen.
How can I show this on the diagram?
I cannot relate the implementation of each Animal with the Role since the animal must be associated with the user

In this design
RoleandAnimalare covariant, because theRolespecialisation express love for correspondingAnimalspecialisations. There is unfortunately no easy way to model this.One way of designing this is to use
pet:Animaland model it with an association. You have then two options:User, that would require the pet type and the role type match. To facilitate this design, I'd even consider making the role's specialisation a template class, i.e.Lover<T:Animal>/). The derivation would be based on the real type of the pet. SO if the pet changes, the derivation could change as well.A better way to design this would be to move the pet from the
Userto theRole. The user has no animal, but in his/her role ofDogLoverhe/she could haveDog(orCatLoveraCat). You can then use association specialization to clearly show the covariance. Several techniques can be used for this purpose as shown in the answers to this other question, for example:This being said, in the real life,
DogLoverandCatLoverare not necessarily incompatible, and one could even have aDogfor historical reasons while being aCatLover. Separating the concerns of ownership and preference, would be an even better design.