[jdom-interest] Element Reference from Attribute

Elliotte Rusty Harold elharo at metalab.unc.edu
Mon Nov 27 11:21:53 PST 2000

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 

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.


| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
|                  The XML Bible (IDG Books, 1999)                   |
|              http://metalab.unc.edu/xml/books/bible/               |
|   http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/   |
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ |
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |

More information about the jdom-interest mailing list