[jdom-interest] Ideas for API changes

Jason Hunter jhunter at collab.net
Sun Apr 29 14:17:35 PDT 2001

> 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.

Node does not take care of this issue!  You removed from your message my
discussion of the problem.  Having node *weakens* type checking.

If Element had an addContent(Node) and Document implemented Node then an
Element could add a Document.  Similarly, if Document has an
addContent(Node) then Document could add more than one element, Document
could add Entity objects which don't belong at the Document level. 
Heck, Documents could add Documents.  

So that means with everything accepting Node is we'd still have to do
lots of runtime checks because not all Nodes are created equal.  I
prefer having the compiler do the checks.  Better to catch errors at
compile time than runtime.  Plus it makes clear to people that Document
only accepts certain types of objects, Element only accepts certain
types, etc.

Also, taking a Node interface parameter isn't really safer than taking
Object because I could still write MyStupidClass implements Node (but
nothing else) and have it added to any Element even though it's not
related to XML.  How would you catch that?  By doing exhaustive runtime
checking within the method?  By just letting this mysterious object be

Another thing:  if Node has getParent() then now Document would have a
getParent() and that doesn't make much sense.  Methods that don't make
much sense is one of the largest problems with DOM.

More issues: Is DocType a Node?  If so, then Elements could also add
DocTypes to themselves.

It sounds simple.  It's not.  Even with Node I believe you'd still want
addContent() to take specific items.  So that advantage is thrown out.


More information about the jdom-interest mailing list