[jdom-interest] RE: [doom-interest] The JDOM Model, Chapter 15 of Processing XML with Java

Elliotte Rusty Harold elharo at metalab.unc.edu
Tue May 7 05:43:29 PDT 2002


At 9:24 AM -0700 5/6/02, O'neil, Jerome wrote:

Some of the original "Java vision" is ultimately at odds with a clear 
API.  In particular, the "no interfaces" idea.  While it may sound 
nice on the surface by keeping things "simple" in that all we have to 
deal with are concrete classes, not having interfaces *doesn't* in 
fact keep things simple.  For an API representing a hierarchical data 
structure, it makes things more complex.  Lets look at your first 
three questions in that context.


JDOM's choice is not "no interfaces". It's no interfaces for the 
fundamental classes. The reasons there isn't a Node interface yet are 
quite different.



The second major complaint I have can be related, but is ultimately 
orthogonal to the interface problem.  It's a stylistic issue that I 
call "Abuse of Collections."  I've always believed (and continue to 
do so) that no publicly defined method should return a collection as 
a result if the members of the collection all share a common data 
type.  It follows that if they all share the same data type, then you 
might as well return an array of them instead, and save your caller a 
cast.

I don't know that it has to be an array. I'd prefer a list of the 
specific object types, such as the NodeList interface used in DOM. 
One of the big things I've noticed is that navigation and search is 
*much* simpler in DOM than JDOM when you're walking the whole tree, 
even before considering the org.w3c.dom.traversal package. A lot of 
this comes from the Node interface and the NodeList class.

In JDOM, all nodes do not, in fact, share a common data type.  This 
makes the collections returned a necessity.  However, it requires 
that the caller do a type check, and then a cast, which is clumsy.


Agreed.
-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|          The XML Bible, 2nd Edition (Hungry Minds, 2001)           |
|             http://www.cafeconleche.org/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.cafeconleche.org/    |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list