[jdom-interest] API inconsistency

Szegedi, Attila szegedi at scriptum.hu
Fri Jun 22 06:14:12 PDT 2001


Speaking of methods common to multiple classes, I feel introducing several
interfaces would allow for writing cleaner code.
Right now, if I want to get the name of a JDOM node, I have to make a bunch
of instanceof calls and casts:

String getNodeName(Object node)
{
  if(node instanceof Element)
    return ((Element)node).getName();
  if(node instanceof Attribute)
    return ((Attribute)node).getName();
  if(node instanceof Entity)
    return ((Entity)node).getName();
  return null;
}

If all classes having getName() would implement the (not-yet-existing) Named
interface, I could do it with single instanceof and cast:

String getNodeName(Object node)
{
  return node instanceof Named ? ((Named)node).getName() : null;
}

Of course, Named would include namespace-related name methods as well.

Same consideration holds for getMixedContent(), getParent(), etc.

Attila.


> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Brett McLaughlin
> Sent: Wednesday, June 20, 2001 5:48 PM
> To: JDOM Interest List
> Subject: Fw: [jdom-interest] API inconsistency
>
>
>
> ----- Original Message -----
> From: "Paul Friedman" <pfriedman at vis.com>
> To: "Brett McLaughlin" <brett at newInstance.com>
> Sent: Tuesday, June 19, 2001 8:14 AM
> Subject: Re: [jdom-interest] API inconsistency
>
>
> > Brett,
> >     Hello. I would like to help in this effort.
> >     My first thought was to systematically go through the API
> > package by package, assigning packages to 'takers'.
> >     Also, I would like to understand your sense of the audit's
> > scope. Please get in touch with me about this task and what you
> > see to be the next steps.
> >
> > pax et bonum. p.
> >
> > ----- Original Message -----
> > Subject: [jdom-interest] API inconsistency
> >
> >
> > > In documenting the API for the 2nd edition of my book,
> I've noticed
> > several
> > > inconsistencies. Like, some constructs have setParent()
> and some don't.
> > Some
> > > have getDocument(), some don't. Anyone want to volunteer
> an "audit" for
> > > these sort of things? We would want to take all the
> common methods from
> > all
> > > the classes like Element and Attribute, and see what they
> are. I think
> > we'll
> > > notice some that are missing, like those above, on
> certain classes. We
> can
> > > then easily add them in, and be happy ;-)
> > >
> > > Takers?
> > > -Brett
> >
> >




More information about the jdom-interest mailing list