Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

IBM question - Student, Instructor

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A partial class diagram of a college course management application is shown in Figure http://certify.torolab.ibm.com/figures/test486F22.gif
studentInstructor. A student knows all of the instructors he is registered with. Similarly, an instructor also knows all the students who are registered with him. A new requirement is
added which specifies that an instructor can also be a student for some courses. What is the BEST partial application redesign shown in the Figure?
a) Design 'A'
b) Design 'B'
c) Design 'C'
d) Design 'D'
e) Design 'E'
Single Select -
OK, I have no clue what the answer should be. I know B is not the answer, but what about others?
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is probably one of the toughest problem I have come across.
If you read the question carefully, there is one thing in common about the Student and the Instructor.Both of them know who has regisitered with each other - A definite case of Generalization, wherein you can identify a common behaviour and define it in the supertype.
Hence A is incorrect.So we have 4 more options left .
B is incorrect.
If you are using generalization, the commonality should be in the superclass.Instead of having methods like getRegisteredInstructors() or getRegisteredStudents(), there should be a method getRegisteredCandidates() in the superclass which would hold the potential candidates - Students or Instructors.
3 more options left .
D and E are incorrect.
Again factoring in the commonality, means making it available in its super-type, not in class(concept) to which it is associated.If getRegisteredCandidates() has to be there, it should be in the Candidate class , not in the Role class, considering that Candidate is the superclass for Student and Instructor.
I think, the aggregration shown in Design E is to make us think in wrong direction.Donot forget the basics - commonality in the supertype.
I am relieved .Only one option left,i.e., C - has to be correct.
It follows the above rule - getRegisteredCandidates() in the super-type.Does it really matter if the super-type is Role and not Candidate?I donot think so.The diagram suggests one or many candidates can play the role of Instructor or Student OR one or many roles(Student or Instructor) could be played by one or many Candidates.It is OK (and probably perfect )
Hope this helps,
-- Sandeep
[This message has been edited by Desai Sandeep (edited May 17, 2001).]
 
Sheriff
Posts: 15768
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Desai Sandeep:
Does it really matter if the super-type is Role and not Candidate?I donot think so.The diagram suggests one or many candidates can play the role of Instructor or Student OR one or many roles(Student or Instructor) could be played by one or many Candidates.It is OK (and probably perfect )
[/B]


I agree that the answer is C but I think that it does matter that Role is the supertype. Peter Coad, in his book "Java Modeling in Color" defines role as one of his four "archetypes" along with Moment-Interval, Party, and Description. A Role is a way of participating in a system. In this case, Student and Instructor would both be roles that a Candidate (which falls under the Party archetype) can take on. That is the reason the other designs would be wrong.
Junilu
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu,
Thanks for the information.I haven't read Peter Coad's book.Let me know, if it is available online.
I selected C based on the following logic :

  1. Student is-a Role.
  2. Instructor is-a Role.
  3. Role can be associated(played by) to one or more Candidates.
  4. One or more Candidates can also play one or more roles.This gives you provision to add more roles other than Student and Instructor in the future.

  5. I am wrong here :


    Does it really matter if the super-type is Role and not Candidate?I donot think so.


    -- Sandeep

 
Junilu Lacar
Sheriff
Posts: 15768
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Desai Sandeep:
Thanks for the information.I haven't read Peter Coad's book.Let me know, if it is available online.


I don't think it's online but you might be able to find some material from it at his company's website. I remember downloading his presentation about Feature Driven Development (FDD) but that was quite a while back.
Junilu
 
Caroline Iux
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both for the answer. I have a follow-up question about how to implement option "C" though. As a instructor student, when I request getRegisteredCandidates, do I get back candidates as my students, or candidates as my instructors?
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caroline,
Since, getRegisteredCandidates() in the Role superclass holds both students or instructors, the implementation of this method should hold a Candidate array for both roles- Student and Instructor.
If you want to hold Candidate of only Student Role, you need to override the method in the Student role.In the overidden method the following validation may be provided:

A similar kind of type check could be done for Instructor role also.
Hope this helps,
-- Sandeep
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could imagine something like this:
In the Role class:

The problem is they don't show this method getRole. I believe C is good as well if you make this jump. A is the only one I see that actually would work in code without any extra puplic interfaces, but I can imagine that the answer would be C. Although incomplete it's definitly the better road to take, I think.

------------------
David Roberts - SCJP2,MCP
 
I found a beautiful pie. And a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic