Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

OO Design Pattern questions in SCJP 1.4 exam?  RSS feed

 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I recently failed to answer one of Marcus Greens mock exam questions. The answer to my opinion was a kind of taste and I would like to know whether such questions really happen in the real exam. Since I plan to go for the exam in Germany next week such types of questions make me a little nervous .

Here the question Marcus Green asked for:

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 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 an 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 signed #2 but the correct answer is #3. The explanation is as follows:

The Correct Answer is
3) Create an employee class with fields for Job title and fields for the other values.

These questions can appear tricky as the whole business of designing class structures is more art than science. It is asking you to decide if an item of data is best represented by the "Is a" or "Has a" relationship. Thus in this case any of the job titles mentioned will always refer to something that "Is a" employee. However the employee "has a" job title that might change.

One of the important points is to ask yourself when creating a class "Could this change into another class at some point in the future". Thus in this example an apprentice chef would hope one day to turn into a chef and if she is very good will one day be head chef. Few other mock exams seem to have this type of questions but they do come up in the real exam.

Can someone explain?
 
Jay Pawar
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objectives set for SCJP1.4, do not mention anything about OO Design.
[ February 12, 2005: Message edited by: Jay Pawar ]
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jay,

what you say is in contrast with what Marcus Green says. So any clearance on this topic is welcome, at least for me

Regards,
Darya
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the Sun objectives

State the benefits of encapsulation in object oriented design and write code that implements tightly encapsulated classes and the relationships "is a" and "has a".

For more information

http://www.jchq.net/certkey/0601certkey.htm
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marcus,

the Sun statement is right in itself. However to my opinion your question does not fit to this statement from Sun.

Did you take this OO design question from a real exam?

Did anyone else see something like this in a real exam
 
Jay Pawar
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Darya,
I did not see any question on the real exam which was even close to Marcus question you have originally posted. Moreover , I studied from K&B book which did not deal with the designing of the classes. However, the book does cover the encapsulation objective as stated by SUN.

Hope this helps you...
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is purely a matter of taste. I'd say either 2 or 3 is correct depending on context.
For example I'd expect a Chef to have a cook(Dish dish) method, an Apprentice to have a cutLettuce(double amount) method, and a HeadChef a hoverOverApprentice(Apprentice apprentice) method, each of which may be inappropriate for the others
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I say in my commentary, designing class is as much art as science. However if you chose option 2 and create an instance of Chef. What happens when they get promoted? What solution would best reflect that possibility if you use inheritance?

If you use the idea of Job title as a field, it is easy to deal with. If My judgement is that the nature of Chefness is the "has a relationship", i.e. has a job title, rather than the "is a" relationship implying more permenance. As you can see from the discussion, this question does promote thought on the nature of the "is a" "has a" relationship.

For the exam you are more likely to be given an example of code and decide if it represents an is-a or has-a relationship than the text scenario I have given.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would be glad when more of you could tell me their opinion so I can weight it and leave that issue out.
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which are you more concerned about, the format/topic of the question or the correctness of my indicated answer?
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The format of your question is what concerns me, because you can argue this way or that way and so can prefer your personal taste for the answer.

What I want to know is whether a question like this happen in a real exam or not.
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't worry about the format, I suspect you will not get a question in this text format. Or to be more explicit, the exam database may contain no questions in this format of presenting a text scenario at all. However you may get questions on the nature of is-a and has-a relationship.

But back to my question, if option 2 is selected, what happens in the case of a member of staff is promoted?
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For SCJP 1.4, is-a and has-a relationship and encapsulation are the only thing you need to know. So, dont worried on that.

For SCJP 1.5, you need to know more, including coupling and cohesion. But as this is not your case, so, you dont have to worry about that.

Nick
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that would all depends on how the data is stored Marcus.
I'd envision the objects themselves to be shortlived, and the data persisted in a relational database.
Therefore when the promoted Chef is read back a new HeadChef object is created.
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeroen, the question is for the purpose of the Java Programmers exam, considerations of the use of databases or not are entirely outside the scope of the question.

Darya, I agree with Nicholas.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your responses. I am sure that for my next step the SCJD I will have to defend any design decision I choose.

But first SCJP. I'm going back to prepare for the real exam and do some mock exams .

Thanks again.
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darya thanks for asking the question in the first place and persisting with your enquiry. Because my question pages have been accessed many hundreds of thousands of times and I have had a great deal of feedback I tend to think they have been entirely debugged. Your question has illustrated this is not entirely so
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!