Reputation: 1644
I think this is relatively simple, but I am just confused since I am new with class diagrams.
I am about to create a program (in Java) about managing the types of employee in McDonalds. So, thought about modelling the objects.
To keep matters simple, there are only two types of employee in McDonalds, "Superviser" and "CrewMember" and both, recieve salary as monthly basis. Furthermore, they both receive a separate kind of bonuses depending on the situation (which, of course could change in future)
So, I began modeling by create a superclass "Employee" with attributes
name
empId
salary
(methods ......etc.)
and incidentally, I made "CrewMember" and "Superviser" are the subclasses of it.
So what my confusion is that if I do model my objects in this way, how is it possible that my instances of "CrewMember" and "Superviser" classes are different from each other?
Please do correct me on how I should model my classes. To make the classes distinguishable, I also thought of adding a type of bonus on each "CrewMember" and "Superviser" but I don't think that would be flexible, if in future, the bonus and the type of bonus would change. So, I am very confused at the moment.
Upvotes: 1
Views: 261
Reputation: 19856
What's the difference between supervisors and crew members?
At least I think you need an association between these two classes modeling that a supervisor is the boss of 1 or more crew members.
If there is anything that a supervisor does but a crew member does not do, then you should model it in the class Supervisor.
If there is no difference between supervisors and crew members, then you don't need the two classes.
Upvotes: 3
Reputation: 15614
To use the concept of inheritance with generalized and specialized cases there should be some motivation what the differences between the entities to be generalized/specialized are. This is called a discriminator - it is some feature (behavioural or structural) that is different. So there needs to be some function that is only applicable to superisors / crew members, some association or attribute. Otherwise it is sufficient to model "employeeType" in the superclass "Employee" for the time begin. Please note that adding inheritance is costly in most development environments. There will be extra source code, extra documentation, extra tables, files and what not later on when you try to get from your model to the implementation. It is not wise to use inheritance (especially implementaiton inheritance) if there is no real benefit by doing so.
Upvotes: 0
Reputation: 20565
Hello thère :) this answer is posted on my iPhone but i Will Update it later! When you make s super class like employee you simply show it in the class diagram by a simple arrow from the super class to the two children classes - i Will find a link in a moment also dó note that it does not matter if the two classes seem identical however it should be clear when the diagram is done! Usually you create a domain model before your class diagram to show these type of inheritances
Upvotes: 0