• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Designing classes

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
A wop bop a lu bop a womp bam boom! Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic