In our lesson our Teacher draw Class relation diagram with UML and Venn diagram.
Salaried Employee inherits Employee Class
Hourly Employee inherits Employee Class
(I do not really remember the context of classes)
He draw Venn diagram like this one :
But ,I really do not believe it should be like this. In my mind it is something like this :
By the way both of us assume classes private parts not included in Diagram representation ,or it would be like 3 set with intersections, for the simplification of diagram.
So my question is simple, which one is right/nearest to right representation.
In some sense they both are.
The first diagram accurately described the inheritance relation between the classes. That diagram is saying "In the set of all employees, some employees are hourly and some are salaried. There is no overlap between them."
Employee
is the more general set, so it contains the two more specific ones.The second diagram is saying "There are employees that are both hourly and salaried. Some of those are employees." This obviously doesn't make a lot of sense in the context of inheritance.
However, the second diagram is a more-or-less accurate representation of what data is shared between those classes. The members of
Hourly Employee
andSalaried Employee
objects will have some overlap, and that overlap is what is contained inEmployee
objects. For example, you might have some class definitions like this:SalariedEmployee
andHourlyEmployee
both inherit theemployee_id
member from their superclass. If you were to draw the class definitions as a Venn diagram, the second diagram you've drawn is roughly what you'd come up with, but in a proper design theEmployee
class would be the entire intersection.You may find it useful to think about inheritance relationships this way, especially as you're learning about OO, but in most contexts you'll find that the second diagram is typically implied rather than stated.