John O'Sullivan [mailto:[EMAIL PROTECTED]] wrote:
>
> >
> > One alternative is what Haggar calls "two-stage construction." Pieces
> > of the construction process that can cause errors are moved into a
> > separate routine. The user constructs an instance, then calls the
> > "finishing" routine and checks the return code or exception from that
> > secondary routine. Yuk.
> >
>
> I quickly looked at the API for JDOM earlier today after seeing the
> first post regarding this question. This API, for the most part, uses
> this "two-stage construction". (Except for a couple of Classes where
> file I/O is used.)
>
> Someone else should take a look and confirm this - I could be wrong.
>
> I don't consider the JDOM API to be yucky at all.
Well, if one principle in idea of "two stage" construction is that the constructor
never performs any operations that might throws exceptions, then JDOM is definitely
*NOT* using two stage construction. Try this little exercise...
import org.jdom.Element;
public class JdomTest
{
public static void main( String[] args )
{
//Classic newbie error.
// The element name parameter is the name only
// without the tag delimiters. Of course,
// those tag characters are not a valid part
// of an element name, so the constructor
// THROWS AN EXCEPTION and never gets to the
// println call.
Element element = new Element("<Element>");
System.out.println( element.getName() );
}
}
Furthermore it seems to me that in two-stage construction the second stage is a
necessary part of the construction too. That is, we cannot consider the object to be
completely instantiated until the second stage has run. I don't know what the "second
stage" of element construction might be (adding Attributes or Child Nodes perhaps?),
but whatever you have in mind, it is not necessary to "complete" the construction of
an Element. The Element is a perfectly well-formed Java object even without any
additional "construction".
The rest of the node classes in JDOM: Document, Attribute, etc. All seem to function
roughly the same way as Element. As do the builder and outputter classes. It seems
to me that the actual classes are using one-stage construction, but a typical
application must do additional "building" with other methods to accomplish anything
useful.
-- Roger
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________