[jdom-interest] insertChild in Element

James W. Howe jwh at allencreek.com
Thu Aug 31 05:39:16 PDT 2000

At 03:12 PM 8/30/2000 -0400, Tom Jenkins wrote:
>Hello all,
> > -----Original Message-----
> > >All these things are easily done with the List returned by getChildren()
> > >using standard Java APIs.  I think it's better to give people access to
> > >the List for them to manipulate as they like than reproduce all the List
> > >functionality in Element.
> > >
> >
> > Lately I'm not so sure of that. Certainly, the getting the children
> > and then operating on the list doesn't seem to be obvious. What if
> > Element and Document implemented List instead of containing a List?
> > Would this be more obvious? Would it be more closely reflect people's
> > mental models of XML elements?
>I don't think Element should implement List.  To my mental model, Element ->
>List is not an "is-a" relation, but rather a "has-a".
>The line:
>         element.getChildren().add(newElement, 3);
>makes perfect sense. But the alternative line:
>         element.add(newElement, 3);
>just doesn't feel right.

I'm not sure whether Element and Document should implement List either, 
however, I do believe that Element and Document should implement whatever 
methods are needed to affect their internal state, if this duplicates List 
protocol then so be it.  My major objection is the notion that Element 
should hand out another object which can then be used to manipulate its 
internal state.  I think this is bad object design.  An Element is an 
object which has children.  It should support direct protocol to manipulate 
its children, not pass off another object which does the work.

James W. Howe				mailto:jwh at allencreek.com
Allen Creek Software, Inc.		pgpkey: http://ic.net/~jwh/pgpkey.html		
Ann Arbor, MI  48103			

More information about the jdom-interest mailing list