This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Designing classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Designing classes" Watch "Designing classes" New topic
Author

Designing classes

Roja Rani
Greenhorn

Joined: Sep 28, 2005
Posts: 22
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

Joined: Feb 26, 2001
Posts: 4782
    
    8

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.


Junilu - [How to Ask Questions] [How to Answer Questions]
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
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
 
wood burning stoves
 
subject: Designing classes