I have come across the following question in mock exam.
You have been asked to create a scheduling system for a hotel and catering organsiation.
You have been given the following information and asked to create a set of classes to represent
On the catering side of the organsiation they have
Head Chefs Chefs Apprentice Chefs
The system needs to store an employeeid, salary and the holiday entitlement
How would you best represent this information in Javae been given the following information and
asked to create a set of classes to represent it.
How would you best represent this information in Java
1) Create classes for Head Chef, Chef, Apprentice Chef and store the other values in fields 2) Create an employee class and derive sub classes for Head Chef, Chef, Apprentice Chef and store
the other values in fields. 3) Create and employee class with fields for Job title and fields for the other values. 4) Create classes for all of the items mentioned and create a container class to represent employees
I answered this with option 2 as all are employees and there may be different responsibilities to HeadChef, Chef and Apprentice and those could be written as methods in respective classes.
But the answer is 3. Anybody please explain how the 3rd option is better than 2nd?
The design choices you make depend heavily on the problem you are trying to solve. Read this article and you'll see there are many ways you can implement Roles (e.g. Head Chef, Chef, Apprentice Chef, etc.)
I'm not sure that the given mock exam problem is representative of the kind of questions that will come out in the exam pertaining to OO design concepts but perhaps the intent of the sample question was to show that you should not try to read anything into the problem other that what is explicitly stated. If all you need to do is store employee id, salary and holiday entitlement, then there is probably be no reason to add complexity by creating subclasses for each role.