[jdom-interest] detach() [eg]
Kenworthy, Edward
edward.kenworthy at exchange.co.uk
Tue Apr 24 23:38:28 PDT 2001
-----Original Message-----
From: Jason Hunter [mailto:jhunter at collab.net]
Sent: 24 April 2001 06:26
To: Joseph Bowbeer
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] detach() [eg]
Joseph Bowbeer wrote:
>
> I'm for either:
>
> (1) Allow the root element to be detached by allowing documents to have a
> null root. Assign the burden of checking for a null root to the client.
> (Part of the client's precondition.)
+I don't like that one at all. Burden should be removed from the client
+wherever possible. Why burden the masses if we can burden the few? :-)
Because OO is about putting responsibility where it belongs, not just piling
it on where it's convenient ;-)
> (2) Prevent the root element from being detached.
+That seems like well-formedness getting in the way. Up til now
+well-formedness has been a Good Thing and on any violation I expect the
+user would say, "Oh, thanks." Like making an element with a space in
+it, or adding an elt as a child of itself. This is the first time a
+well-formedness check would have the user say, "Damn, just do what I
+said."
Agreed, but the Document should know it's no longer in a valid state,
therefore there are things the user can't do with it until it's fixed.
> No one likes placeholder (3), except perhaps as the lesser of evils.
:-)
I actually think a placeholder *is* an evil in this case as it masks the
real error.
How do you work out your Document has an invalid root ?
> As for IllegalStateException (4), I don't like it because of its time bomb
> nature. Compared to a null root, IllegalStateException makes it harder
for
> clients to determine the state of a given document (calling getRootElement
> would throw an IllegalStateException, right?), and it gives the clients no
> discretion in determining whether an empty document is in fact a legal
> argument or not.
+Almost no one would ever see the ISE. Only if you detached a root and
+then later actually cared about the doc. I find that unlikely. I'm
+sure people could write in many use cases for detaching the root, but
+none of them would care about the document afterward. It's throw-away.
+So we let the root leave the document, and we put up a warning flag in
+case someone tries to use the doc later. I've been convinced a warning
+flag is better than an internal sweep-it-under-the-rug.
Indeed. 100%. If you detach the root that means one of three things a) you
meant to do it and you're not going to use the document anymore b) you meant
to do it and are going to handle putting it back in a valid state because
only you know what you want c) it's a bug in the logic of your application
and an exception will help you find the bug.
Edward
___________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
More information about the jdom-interest
mailing list