Andreas,

Thank you for your suggestion. This does make sense. However, I'd
still have to check for appropriate values in the constructor of the
new TYPE designated to hold the values.

Still, this is probably a better alternative. It means the validation
only occurs once in the code (in the new types constructor) and not in
multiple places in the code. If I made the new type immutable (which
is reasonable since it is a value type) then I wouldn't have to worry
about subsequent modifications to the object creating an invalid
value.

I will have to think on this some more.

Landon

On Feb 5, 2008 12:25 AM, Andreas Schmitz <[EMAIL PROTECTED]> wrote:
> 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
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFHqB2C737OVr+Ru7oRAuk/AKCFIJwJGg+oCKsw3b6DiOLpT/dwhwCgsDbq
> wF/k55GNzZl0rhie28ybJbM=
> =J047
> -----END PGP 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
>
>

-------------------------------------------------------------------------
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

Reply via email to