[jdom-interest] Re: Subclassing Element vs Element Context

Joseph Bowbeer jozart at csi.com
Thu Nov 16 14:18:01 PST 2000


> I understand that the thinking so far is that ...

It's not my thinking, for one.  Subclassing to add an extra field may
also require overriding read/writeObject, clone(), equals() and
hashCode() -- depending on how Element is implemented.

Providing a generic implementation of these that takes a generic
userObject into account may be a time-saving convenience for the users
that need this kind of thing.

It's hard to argue this effectively without a concrete example, though.

-----

Patrick Dowler writes:

I understand that the thinking so far is that a subclass with user data
(which isn't really in any danger of breaking when the base class
changes, BTW) is the better route because you get type-safety for your
app and you can do the software engineering thing and ensure some sort
of state-invariant. A generic user object doesn't let you have either,
so anything beyond a trivial project wouldn't likey use it anway.

-----

From: "Joseph Bowbeer" <jozart at csi.com>
To: "Patrick Dowler" <Patrick.Dowler at nrc.ca>
Cc: <jdom-interest at jdom.org>
Sent: Monday, November 06, 2000 4:29 PM
Subject: Re: [jdom-interest] Re: Subclassing Element vs Element Context


Right.  I misused the term "fragile".  I think any subclass carries some
extra baggage, but not all subclasses are fragile.

I think the most fragile subclass in this case is the custom SAXBuilder
required to construct the custom Element subclasses.

The most fragile things about subclassing Element itself are the aspects
dealing with serialization, equals, hashCode, and Cloneable.  How
difficult these are depend on the implementation details, such as
whether the extra field is declared to be transient or not, whether
Element declares its own serialization version id, and whether (and how)
Element overrides equals, hashCode and clone.

-----

From: "Patrick Dowler" <Patrick.Dowler at nrc.ca>
To: "Joseph Bowbeer" <jozart at csi.com>; <jdom-interest at jdom.org>
Sent: Monday, November 06, 2000 3:31 PM
Subject: Re: [jdom-interest] Re: Subclassing Element vs Element Context

On Sat, 04 Nov 2000, Joseph Bowbeer wrote:
> Adding a userObject can accomplish a lot without forcing
> the user to subclass or to provide an external mapping.

On the other hand, subclassing for the purpose of adding a user object
and associated methods (ie. without overriding existiing behaviour) is
trivial and basically safe from delicate subclassing problems.





More information about the jdom-interest mailing list