Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Builder argument swap

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: jcowan AT reutershealth.com
  • To: Elliotte Harold - java FAQ <elharo AT metalab.unc.edu>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] Builder argument swap
  • Date: Fri, 19 Mar 2004 13:27:50 -0500

Elliotte Harold - java FAQ scripsit:

> public Document build(String systemID);
> public Document build(String document, String baseURI);
>
> Yesterday it occurred to me that the second one is backwards. In keeping
> with the general principle of overloading methods by adding successive
> arguments (Does anyone have a reference on that?)

I think nobody has documented the design pattern "Argument Order" before,
but the idea is to push optional arguments to the right. Overloading is how
Java does optional arguments.

> I think these should be:
>
> public Document build(String systemID);
> public Document build(String baseURI, String document);

No, I think you have it correct already. Conceptually, the build()
multimethod takes two arguments, a source and an optional base URI.
Currently, the source can be a File, an InputStream, a Reader, a system
ID (represented as a String), or a String. Since the last two have
the same representation, you're forced to make the base URI prohibited
when the source is a system ID (which is reasonable) and required when
the source is a String (which is also reasonable, as there is no way to
deduce the base URI of a String). There is no obvious reason, though,
why a base URI can't be set when the source is a File.

That said, it's not very clear to me why you want to support File
or String as sources anyhow; it's soooo trivial to wrap the File in
a FileInputStream and the String in a StringReader. It seems to me
like clutter. If you want, mention FileInputStream and StringReader in the
documentation.

> Then, maybe one of the arguments should be renamed; e.g.

System IDs aren't base URIs, though they have the same syntax.

--
John Cowan www.ccil.org/~cowan www.reutershealth.com
jcowan AT reutershealth.com
[T]here is a Darwinian explanation for the refusal to accept Darwin.
Given the very pessimistic conclusions about moral purpose to which his
theory drives us, and given the importance of a sense of moral purpose
in helping us cope with life, a refusal to believe Darwin's theory may
have important survival value. --Ian Johnston




Archive powered by MHonArc 2.6.24.

Top of Page