|
Post by R on Jan 31, 2002 17:59:57 GMT -5
and I thought 108 took the fun out of CS.
|
|
|
Post by R on Jan 31, 2002 23:31:29 GMT -5
can someone direct me to website where I can fully understand iterators?
|
|
|
Post by Sylph on Feb 1, 2002 22:58:47 GMT -5
what does the "implements Iterator" part in the header do to a class?
|
|
|
Post by Random_Death on Feb 1, 2002 23:46:58 GMT -5
I'll try to explain it to the best of my understanding...
Basically an iterator is a way/process/structore/pattern or whatever that's common programming. Apparantly in Object Oriented programming you may need to go through a list in this fasion, where you have the list and ask(using hasNext()) if there's another thing in it that you haven't seen yet. If it says yes then you can get (using next()) this object to process or whatever your going to do with the damn thing. And it may be possible to remove the object you just got a look at using (remove()).
When you make a class and then put "implements Iterator" your making a promise that your class will have these 3 methods that will do these things. And of course the title or the class description will tell the user what kind of list it goes through and stuff. So basically you promise that your class will conform to this design/standard.
Whew, I hope there's an ounce of accuracy in everything i just said. Hope.... Oh well, I could be wrong. Anyone have another or a clearer or more accurate and more helpful interpetation of iterators.
|
|
|
Post by Sky on Feb 2, 2002 20:49:33 GMT -5
hey...u sound so much like the prof...are u Paul Gries???...haha j/k...u must be a super fan of him anyway ;D ;D ;D
what u said are pretty much the ideas of the assignment...just have to mention that the user may not always calls for the hasNext() method before asking for the next object...
|
|
|
Post by Sylph on Feb 2, 2002 21:17:35 GMT -5
... the user may not always calls for the hasNext() method before asking for the next object... really? it's not a precondition? what's supposed to happen if hasNext() == false and they call for the next object?
|
|
|
Post by Sky on Feb 2, 2002 23:36:42 GMT -5
i think i saw it somewhere in the newsgroup...it said that it's safe to return null if the tag does not exist... here (copied from the newsgroup): If you read about the Iterator interface in your java API, you'll see that when there are no elements left, next() throws an exception. You haven't covered exceptions (or if you very recently have, it's not the point of this assignment... that will be later). When usuing Iterators/Enumerations, normally one calls hasNext() to ensure that something still exists before you call next(). I think it's safe to return null, but be sure that you mention that in your method header comment. Remember, returning null should not really be a special case to handle based on the hints given.
|
|
|
Post by Random_Death on Feb 3, 2002 22:26:55 GMT -5
Nope, I'm not Paul Gries. Wait, let me check... oh see, I don't have the right colour skin. Hmm... and no I'm not a super fan of him.
|
|