Sunburned Surveyor wrote: Hi,
> I have another short "Java Programming In General" question. (All of > these questions are related to my work on the JTSWarped Library, so I > hope it will be useful to OpenJUMP developers at some point in the > future.) > > When is it appropriate to validate mathod arguments when using a Java > library? Should this be done by the client code that uses the library > BEFORE arguments are passed to the library code, or should it be done > AFTER the client code has made the method call, within the library > code? > > For example: JTSWarped has code that will accept a String representing > an angle in Degrees-Minutes-Seconds format that returns the same angle > in Decimal Degrees format. Should I check for a valid String argument > within this method, or should I indicate that this responsibility > belongs to the client code? > > Here is why I ask. I've been reading about the proper use of Java > Exceptions. Most of the material I've read seems to indicate that > Exceptions generated by improper use of an API (invalid method > arguments as an example) should throw unchecked Exceptions. This makes > sense if the client code is responsible for the validity of method > arguments. If the library code is responsible, it seems more > reasonable to throw checked Exceptions. there are many positions on this, varying a great deal. Personally, I'd check as much as possible by using appropriate argument TYPES. For example, don't use a String as argument, use a class that already performed this check and has a degrees, minutes and seconds field. By using an appropriate argument type, the client and the library both don't have to perform this check, only the party which instantiates a value of the type. Best regards, Andreas -- l a t / l o n GmbH Aennchenstrasse 19 53177 Bonn, Germany phone ++49 +228 18496-11 fax ++49 +228 1849629 http://www.lat-lon.de http://www.deegree.org
signature.asc
Description: Digital signature
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel