[jdom-interest] Ideas for API changes

Elliotte Rusty Harold elharo at metalab.unc.edu
Sat Apr 28 17:33:54 PDT 2001


At 3:43 PM -0700 4/28/01, Jason Hunter wrote:


>Here's my challenge to you:  Figure out the interface of Item.  Keep in
>mind that any method declared should be useful across all classes
>implementing the interface.  And keep in mind the interface should be
>useful for more than just being a common base interface.  Object is good
>enough at being a common base; there would need to be extra value.
>

I'm not sure there needs to be more than that. I think having the 
common type alone because it really strengthens type checking 
throughout the API and makes a lot of code simpler. For instance, in 
addContent() we no longer need to check for seven different types at 
runtime before adding the object. All the checks can be performed at 
compile time. I don't know that this would be significantly faster, 
but it would be conceptually much simpler.

On a similar line, I don't feel Object is good enough as a common 
base class because a method that takes an Object as an argument 
implies to me that it can indeed take any object but our methods 
can't. This seems to cry out for a Node interface. The case where 
methods do take any objects as arguments, and to which me are most 
similar, the Java Collections API, indeed does allow any object types 
as arguments.

However, I do think they're a couple of methods that would be useful 
in the Node interface. At a minimum I'd say getParent() and 
getDocument(). I think we might also want to look at (though perhaps 
in 1.1) a getValue() method which returns the XPath value of a Node. 
This is a very useful thing to have even if you're not using XPath, 
and it is genuinely applicable to all node types, (as opposed to DOM 
nodes, some of which have null values.) I also think we could 
plausibly put hasChildren() and getChildren() in the Node interface.



-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|                  The XML Bible (IDG Books, 1999)                   |
|              http://metalab.unc.edu/xml/books/bible/               |
|   http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ |
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list