[jdom-interest] insertChild in Element
James W. Howe
jwh at allencreek.com
Thu Aug 31 05:51:06 PDT 2000
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.
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.
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
More information about the jdom-interest