[jdom-interest] insertChild in Element

Patrick Dowler Patrick.Dowler at nrc.ca
Thu Aug 31 15:15:12 PDT 2000


On Thu, 31 Aug 2000, Brett McLaughlin wrote:
> 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.

"good programming principles" should be followed whenever there is a
choice and both avenues look equally good. Here the argument is clearly
"good programming principles" vs. "lean API". I'm in favour of a lean API,
and the proxy pattern (a la "Element implements List") means we just add
a bunch of methods like:

public Object get(int i)
{
	return data.get(i);
}

Does it buy us much over having just "List getChildren()", which you can do
what you like with?

In the "do what you like" category - unfortunately - is that you can add any
arbitrary object. We lose type safety by exposing a live List to the programmer
due to the non-type-safe containers :-( This is a very large blow to
"good programming principles", IMO.

Personally, I would not expose the List for this reason alone because the
compiler can no longer catch simple errors. At best, we could add code
to the PartialList class to check types and throw a RuntimeException,
but the lack of a base interface or class makes that pretty messy now as
well, not to mention inefficient. Otherwise, get ready for ClassCastException...

--

Patrick Dowler
Canadian Astronomy Data Centre




More information about the jdom-interest mailing list