• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Designing classes

 
Roja Rani
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

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

it.

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?
 
Junilu Lacar
Bartender
Posts: 7600
53
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



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.



Here all the 3...Head Chef, Chef, Apprentice Chef are basically employees having the same attributes ..with different designation..

If this difference can be captured in an attribute Job...then you dont need

need to have each class for each type of the user.

Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic