[jdom-interest] Re: Interfaces? (was: W3 DOM support)

Alex Chaffee guru at edamame.stinky.com
Sat Aug 5 11:06:47 PDT 2000

On Sat, Aug 05, 2000 at 12:00:39AM -0700, Joe Bowbeer wrote:
> I agree with Louis that "articulating" the JDOM object structure into
> Interface, AbstractClass, and DefaultImplementaion could open more
> doors, but I'm not convinced that those doors need opening right now.

We don't necessarily need both an abstract class and a default
implementation, but I've gotten so much mileage from separating
Interface and Implementation that I would vote +1 for defining Element
et al. as interfaces in a heartbeat.

> I do disagree with Jason on one point: I don't believe that adding
> interfaces means having to use factories.  Internally yes (and that may
> be what is meant), but I think the user can avoid factories by sticking
> to the default implementations.  For example, IElement would be the
> interface and Element would be the default implementation.

If we do use interfaces, they should be named for what they are, and
the implementation classes will just have to have the funny names. IMHO.

Anyway, what's wrong with factories? We use factories now! The "input"
classes SAXBuilder and DOMBuilder are actually factories. 

The only time we create instances ourselves is when assembling a tree
in memory, and I'm not sure that happens often enough to justify
abandoning all the other advantages of splitting into interfaces.

Furthermore, what's the big difference between

 Element e = new Element();


 Element e = Element.newInstance();


> And I'm not a big fan of subclassing.  I'd rather delegate.  To my mind,
> subclassing is a fragile, often requiring intimate knowledge of the
> source code and leaving oneself vulnerable to future revisions of the
> base classes.

Hear, hear!  Inheritance is OOP for the weak!  Delegation rules.

> For my uses of JDOM, though, leaving out interfaces seems good enough
> for now.  Extracting interfaces could be a 2.0 thing, no?

Sounds fine to me.

> Jason Hunter wrote:
> > It makes for a cleaner, easier-to-understand system
> > and makes creating documents MUCH easier.
> > With interfaces you have to use factories to create
> > everything,

see above

> >  and you get into issues when moving
> > elements created with one factory into documents
> > created with another.

The issues can be resolved by the authors of the classes making proper
use of types in variable declarations.  Of course, some optimization
can occur if you know which implementation of Foo you're dealing with,
but these optimizations can be bracketed with "instanceof" statements.

Yes, it's a pain, I admit, but again: I think it's worth it.

> Louis Tribble wrote:
> > > My instinct is that interfaces are also better for
> > > alternate implementations of the "pure" API. The
> > > lazy Builder on the wish list, or an implementation
> > > that supports persistence and/or transactional
> > > updates, for example.
> Jason Hunter wrote:
> > Subclassing can handle those tasks.  You do have
> > to do more work than with the classic JDOM classes,
> > but only as much work as you'd have to do using
> > interfaces, and with interfaces you'd have to do that
> > work for everything.

No; there can be default base classes that do all the boring stuff,
like the Element class does now.  Note: I didn't say abstract classes.

> > Heck, you can subclass Element and reimplement
> > every method if you want, treating it like an interface.
> > Well, except for the final methods, and really our
> > ability to declare finals (for equals() for example) is
> > another advantage of concrete classes.

Hmm, good point about finals.

Alex Chaffee                       mailto:alex at jguru.com
jGuru - Java News and FAQs         http://www.jguru.com/alex/
Creator of Gamelan                 http://www.gamelan.com/
Founder of Purple Technology       http://www.purpletech.com/
Curator of Stinky Art Collective   http://www.stinky.com/

Received: from mb07.swip.net (mb07.swip.net [])
	by dorothy.denveronline.net (8.9.3/8.9.3) with ESMTP id EAA19087
	for <jdom-interest at jdom.org>; Sun, 6 Aug 2000 04:32:31 -0600 (MDT)
Received: from anders (d212-151-94-101.swipnet.se []) 
          by mb07.swip.net (8.8.8/8.8.8) with SMTP 
          id MAA14307 for <jdom-interest at jdom.org>; 
          Sun, 6 Aug 2000 12:31:56 +0200 (MET DST)
Message-ID: <005d01bfff90$f5361900$655e97d4 at anders>
From: "Anders Dahlberg" <anders_dahlberg at swipnet.se>
To: <jdom-interest at jdom.org>
Date: Sun, 6 Aug 2000 12:27:43 +0200
MIME-Version: 1.0
Content-Type: multipart/alternative;
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.00.2314.1300
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Subject: [jdom-interest] IOException when trying to build jdom with ant
Sender: jdom-interest-admin at jdom.org
Errors-To: jdom-interest-admin at jdom.org
X-BeenThere: jdom-interest at jdom.org
X-Mailman-Version: 2.0beta2
Precedence: bulk
List-Id: JDOM Mailing List for General Issues and Updates <jdom-interest.jdom.org>

This is a multi-part message in MIME format.

Content-Type: text/plain;
Content-Transfer-Encoding: quoted-printable

I've got windows 98 running on a pentium mmx 200

Here is the error:
Java and XML Build System
Building with classpath =
Starting Ant...
Buildfile: build.xml
BUILD CONFIG ERROR: Can't open config file: build.xml due to: =
n: java.lang.reflect.InvocationTargetException
org.apache.tools.ant.BuildException: Can't open config file: build.xml =
due to: j
ava.io.IOException: java.lang.reflect.InvocationTargetException
        at =
        at org.apache.tools.ant.Main.runBuild(Compiled Code)
        at org.apache.tools.ant.Main.main(Compiled Code)

Content-Type: text/html;
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<META content=3D"text/html; charset=3Diso-8859-1" =
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"Times New Roman">
<DIV><FONT face=3D"Times New Roman">I've got windows 98 running on a =
pentium mmx=20
<DIV><FONT face=3D"Times New Roman">Here is the error:</FONT></DIV>
<DIV><FONT face=3D"Times New Roman"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Times New =
Roman">C:\Anders\java\xml\jdom&gt;build<BR>Java and=20
XML Build System<BR>-------------------<BR>Building with classpath=20
Ant...<BR>Buildfile: build.xml<BR>BUILD CONFIG ERROR: Can't open config =
build.xml due to: java.io.IOExceptio<BR>n:=20
Can't open config file: build.xml due to: j<BR>ava.io.IOException:=20
at org.apache.tools.ant.Main.runBuild(Compiled=20
Code)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at=20


More information about the jdom-interest mailing list