File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Cattle Drive and the fly likes OOP-4 hints please. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "OOP-4 hints please." Watch "OOP-4 hints please." New topic
Author

OOP-4 hints please.

Richard Boren
Ranch Hand

Joined: Mar 01, 2001
Posts: 233
I am stuck
I do not understand one of the nitpicks I got.
The basic logic behind my program is to except a serial number as a command line argument then retrieve the description from the HashMap using the serial number. After retrieving the description I use an if/else construct to instantiated the desired object based on the passed in serial number. I use the follow basic setup for object creation:

where each Child class extends AbstractParentClass and overrides an AbstractParentClass's method.
Is the if/else stuff wrong? Am I not doing polymorphism? The object created is not known until runtime and I have followed the examples in the books, so I was under the impression I was doing polymorphism. I looked at putting the different objects in an array, but didn't see the point in it. Or am I just missing the point of the remark (nitpick) all together.
I can already hear myself saying "duh!" and leaving a red mark on my forehead

[This message has been edited by Richard Boren (edited June 28, 2001).]
Amber Woods
Ranch Hand

Joined: Mar 28, 2001
Posts: 111
Hey Richard,
I have not been nitpicked for this one yet but I will try to guide you.
First of all I have four classes for this prog besides Lookup. All Lookup does is create static hashmap that contains a dozen things to rent, meaning a couple of videos, pieces of furniture, and some books on tape. I created 12 of these objects using their particuliar class (Video class for videos and so on). That way all my Lookup in main has to do is see if the serialnumber taken in is in the hashmap and if it is just print the description using the method getDescription for the object from the hashmap. My main in lookup only contains about 16 lines.
I hope I am not giving away too much. HTH
JDJ, Just erase anything if you think it is too much.
I went ahead and deleted a line because I thought it gave away a little much.
[This message has been edited by Amber Woods (edited June 28, 2001).]


"Happiness is a way to Travel, <b>Not</b> a Destination" -- Unknown
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1751
    
    2
Like Amber, I haven't been nitpicked for this one either. My version sounds remarkably the same as Amber's.
Originally posted by Richard Boren:
The basic logic behind my program is to except a serial number as a command line argument then retrieve the description from the HashMap using the serial number.

Why not retrieve the object itself from the HashMap? According to the assignment, any rentable Thing object should have a getDescription() method.
After retrieving the description I use an if/else construct to instantiated the desired object based on the passed in serial number.

Why do you need to instantiate objects here at all? Presumably all the objects you want are stored in the HashMap.
Richard Boren
Ranch Hand

Joined: Mar 01, 2001
Posts: 233
Over looking puting the objects in the HashMap was my major down fall.
Now that Amber's got me back on track I think I'll be able to finish the assignment. I was following the examples in the books a little to closely. I was blinded by the knowledge Hey this is a big step for me. And boy does my forehead hurt "DUH!!!".
Thanks Amber and Michael.
Do you think I should delete this thread?
Amber Woods
Ranch Hand

Joined: Mar 28, 2001
Posts: 111
Glad to be of service
I would let JDJ decide whether to delete the thread.
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1751
    
    2
As far as deleting the thread -- I don't know. I think the assignment itself is pretty explicit. I don't think we went into much more detail than the assignment.
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
First off all I dont have a problem with anything posted here. I will however ask Paul to check, to be on the safe side.
Secondly Richard I did exactly the same and Marilyn nitpicked me towards the solution. Must say she did take her time doing it though, what Amber & Micheal said in one posting she did in 3 or 4 nitpicks . But man the feeling when I finally saw it.
It was my OO moment !!!
Good luck Richard
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1751
    
    2
Yep -- isn't polymorphism cool.
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
I just finished Lookup, and I have to say that this has been the most fun program(s) so far. I did the same thing as Amber and Michael. I am looking forward to getting nitpicked on it. I guess its time to start looking for a good book on Servlets.
Matthew Phillips


Matthew Phillips
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
To Matthew and others working ahead.
The example in the assigment of servlets is good for Servlets 1.
So that does not nead a book.
The challange comes with Servlets 4b it is something like 'Say' and without some help of a book it will be rather tough.
Probably the Api-doc of servlets should suffice you should look for e.g. servlet-2_3-pfd2-docs.zip see http://java.sun.com/products/servlet/download.html
And to OO-4. The figure in the Assigment for OO-4 should give you a (the) good hint!

[This message has been edited by Peter Gragert (edited June 29, 2001).]
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20639
    ∞

I've been asked to take a look at this thread.
I remember this submission. Marilyn passed it on to me and asked me to comment on it. So the offending nitpick is mine.
One of the purposes of this assignment is to introduce polymorphism. My impression was that there was no polymorphism being used in the submission.

permaculture Wood Burning Stoves 2.0 - 4-DVD set
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OOP-4 hints please.