[jdom-interest] Element Reference from Attribute
James Strachan
james at metastuff.com
Tue Nov 28 01:51:46 PST 2000
----- Original Message -----
From: "Elliotte Rusty Harold" <elharo at metalab.unc.edu>
> I was reading Bertrand Meyer's Object Oriented Software Construction
> over the holiday (definitely heavy thinking) and that gave me a new
> perspective on part of the debate in this thread. Meyer talks about
> the notion of trading storage for computation in features (method
> calls, to Java programmers) and I think maybe that's what we need
> here for the getParent() method. In brief:
>
> 1. All nodes classes (Element, Attribute, ProcessingInstruction,
> etc.) have a getParent() method that behaves correctly; i.e. it
> returns a reference to the parent unless there is no parent in which
> case it returns null. This method never throws an
> UnsupportedOperationException or anything similar.
>
> 2. In some classes this method will be implemented via storage; that
> is, each object will hold a reference to its parent which is simply
> returned.
>
> 3. In other classes, this method is implemented via computation; i.e.
> walk the whole document tree to find the parent but don't store it.
>
> Individual programmers could use the builder/factories to decide
> which version they wanted. However, the key idea is that in all cases
> the API and behavior is the same. Each programmer gets to decide
> whether they care more about storage or computation. This might
> however be an issue for 1.1. For 1.0 I recommend using the simpler
> solution, storage. We can add the computational option in 1.1.
The general principle is good and can be used effectively in areas of JDOM.
It basically amounts to the phrase "caching".
For example, in the current version, Element is doubly linked and has a
getDocument() method which computes its value rather than using storage.
Some developers may wish to derive to use storage to cache this which would
improve performance for largely nested trees. Similarly we can use this
technique to cache the result of getChild() / getChildren() / getAttribute()
for times when the storage - computation tradeoff is worth it.
However in the singly linked tree debate this technique does not apply. We
want nodes to be sharable, usable across documents and elements plus we
don't want the extra memory overhead of storing any kind of parent; Element
or Document. So computation is not possible since there is no Document or
Element parent to navigate.
<James/>
James Strachan
=============
email: james at metastuff.com
web: http://www.metastuff.com
If you are not the addressee of this confidential e-mail and any
attachments, please delete it and inform the sender; unauthorised
redistribution or publication is prohibited. Views expressed are those of
the author and do not necessarily represent those of Citria Limited.
More information about the jdom-interest
mailing list