[jdom-interest] insertChild in Element

Brett McLaughlin brett.mclaughlin at lutris.com
Thu Aug 31 08:03:30 PDT 2000

"James W. Howe" wrote:
> At 06:31 PM 8/30/2000 +0200, Jason Hunter wrote:
> > > It seems to me that the ability to insert a child into an
> > > Element at a particular location is behavior which belongs to the
> > > Element itself.  I
> > > would advocate adding this capability to Element.
> >
> >Then you need the ability to remove a particular child by index too.
> >And the ability to remove all children, remove a child by name, remove
> >all children with a name, add a set of children, remove a set of
> >children, and so on.
> >
> >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.
> >
> >-jh-
> This is where I would disagree.  If it is appropriate for someone to be
> able to manipulate the children of an Element, it should be done through
> the Element itself, not through some third party object.  Element should
> support any and all methods which are appropriate to manipulating its
> internal state.  If that means duplicating the List protocol, so be it.

OK, I think we can pretty much resolve this. I've seen two folks that
want this functionality, you and Trevor Rude. And I know that Jason and
I are in consensus that it really isn't needed. There is a real danger
of API bloat in doing what you propose. I've also yet to see any
use-case (referring to "good programming principles" just doesn't do it)
for the need for this. Finally, every Java 2 developer is familiar with
Collections, or should be. So I think it's safe to say that while this
was good discussion, I'm even more convinced that getting the List and
operating on it is sufficient. It would create at least 10-15 new
methods that are exact copies of List methods, with new names!!, and not
add any new functionality.


> A user should be able to look at the public protocol of Element and be able
> to see everything that can be done by/to an Element.  Right now, the public
> protocol is actually split between the Element itself and the List of
> children it returns.  You can talk to an Element to add/get/remove a child
> but if you want to do other things you have to first get the List and then
> manipulate the list.  This strikes me as bad design.  It doesn't seem right
> that some manipulations of the children are done through Element and others
> are done by first obtaining the list.
> James W. Howe                           mailto:jwh at allencreek.com
> Allen Creek Software, Inc.              pgpkey: http://ic.net/~jwh/pgpkey.html
> Ann Arbor, MI  48103

Brett McLaughlin, Enhydra Strategist
Lutris Technologies, Inc. 
1200 Pacific Avenue, Suite 300 
Santa Cruz, CA 95060 USA 

More information about the jdom-interest mailing list