|
Post by Sylph on Mar 17, 2002 0:29:25 GMT -5
since i lost a lot of marks on a3 for not throwing an exception every time i had a Requires clause, i have a question... e.g. // Requires: iterator must only contain URLTreeNodes ==> how do i make sure iterator only has URLTreeNodes beforehand so i can throw an exception?
|
|
|
Post by gabbie on Mar 17, 2002 0:58:14 GMT -5
if/else statement if (doesn't contain URLTreeNodes) throw exception else if(contains URLTreeNodes) proceed with method.
is that your question ?
|
|
|
Post by Sky on Mar 17, 2002 1:17:51 GMT -5
Sylph...i don't think your requires clause is valid... didn't your program create an iterator internally...and it is not given by the user...so reasonably it's the programmer's responsibilities to make sure iterator only contain URLTreeNodes... i think requires clause is like preconditions...it's to tell the user under what conditions the program will crash...so it has to do with what parameter the method gets...i didn't use any require clause in a4...cuz all the user going to input is string...and all valid urls (other methods with all kinds of different parameters are private methods..the user can't call them)...so i can't think of any reason that the program will crash if u done it correctly
btw...an iterator is used to process the elements in a list...it doesn't contain any elements in it...so it doesn't contain URLTreeNodes...i guess u mean the list only contains URLTreeNOde in the requires clause...and that's also the programmer's responsibility since the user can't add anything into the list except urls which is inside an URLTreeNode...
|
|
|
Post by Sylph on Mar 17, 2002 10:26:13 GMT -5
Sky, so you don't need a Requires clause for private methods?
|
|
|
Post by Random_Death on Mar 17, 2002 19:23:25 GMT -5
If there's a requirement for the method to work as specified then you need to write a require's clause.
It doesn't matter if it's a private or public method.
|
|