[jdom-interest] children as List

Cameron Smith cameron.smith at entranet.co.uk
Fri Sep 1 02:51:18 PDT 2000

I think its the right decision to present the children of an Element as a
List rather than having List-like behaviour in Element itself.

This is because:
1)  List is almost a 'basic type' now in java: so using it is 'second
nature', as opposed to NodeList in DOM.
2)  If we take the idea of 'pure objects' to the extreme then every class we
create which has a variable number of a certain type of object would need
its own 'list-style' interface.  Instead, whenever I see a '1-n'
relationship between parent and children I think of a 'List' or 'Iterator'
interface to provide access to it.

The main downside of this is the vulnerability of exposing the List to
mangling by user code.   However user code which wants to protect itself
(and in many cases will /want/ to be mangling the List) from this can use
the Collections.unmodifiableList() method.  

Another issue was ClassCastExceptions.  I think this is more an issue of
whether or not there should be a unified class hierarchy in JDom, so that
everything can be safely cast to 'Element', (like Node in DOM) than an issue
about where to put List behaviour.

	Cameron Smith, Software Developer
	Entranet Ltd

More information about the jdom-interest mailing list