2

My teacher gave us a homework to draw a class diagram using something like this

class PersonRole{}

class Employee{
 isA PersonRole;
}
class Manager {
 isA Employee;
 0..1 -- * Employee;
}

I know in order to draw a reflexive association, both instances has to have same class(is that correct?)

But in this instance, manager inherits from employee, and employee inherits from personrole.
So can I say both of their class are personrole and draw a reflexive association between them? If not, do I just Draw generalization and association?

i tried to draw normal reflexive line like this enter image description here

but it feels weird

I also tried this

enter image description here

Feels OK but I wonder if using reflexive is possible

Christophe
  • 68,716
  • 7
  • 72
  • 138
AmazingEgg
  • 23
  • 2

1 Answers1

0

Your first attempt uses a reflexive association. It is not wrong but does not at all correspond to your design:

  • it assumes that every person has potentiallly employees and a manager.
  • It does not define other classes, but just properties that are not in the code for personRole.
  • as a consequence, manager and employee could not have different behaviors.

Your second design doesn't use reflexive associations, and corresponds to your narrative. There is no issue having an association and a generalization between the same classes.

A third option could use a reflexive association on employee, but keep manager as a specialisation on employee. This design deviates from the narrative, could allow managers to have different properties and behaviours. But it implies also that employees could report to non-managers (e.g.team leads that have not a formal management role).

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • Thank you for your helping! But why every person could potentially be a employee or manager? – AmazingEgg Mar 20 '23 at 09:02
  • @AmazingEgg Thanks! Because in your first diagram personRole can have many employees, and 0..1 manager (that's what the reflexive asso says). Any class inheriting personRole would also inherit its associations. This is different from your secondiagram where personRole could represent non-working persons, without the risk of linking them to an employee or manager by accident – Christophe Mar 20 '23 at 20:07