[jdom-interest] Text class (Modified)

philip.nelson at omniresources.com philip.nelson at omniresources.com
Mon May 28 09:34:28 PDT 2001


> >public class Text {
> >
> >     private StringBuffer value;
> >     private Element parent;
> >
> >     protected Text() { }
> >
> 
> I guess I've never really understood why JDOM has these protected 
> noargs constructors. A subclass of a Text is still a Text, and should 
> still be able to rely on all the other public methods in the Text 
> class. These methods will fail unexpectedly if this constructor is 
> used. Why do we need this constructor at all. Why can't subclasses 
> use the normal public constructor that does ask the caller to provide 
> a String?
> 
> Same question for the other constructors like this in the 
> other core classes.

It allows you to basically start over with your subclass and just use the
interface of the base class.  Without this constructor, I can't be sure that
a change in the subclass won't affect my totally rewritten subclass.  It
also gives you, in the case of JDOM anyway, an almost abstract interface to
implement.  Since the member variables are not assigned, it's pretty close
to having an interface to work with.

I am not so sure private member variables make sense.  We have been somewhat
inconsistent with this but I think a subclass friendly base class will have
protected members.  We do this in Element and Attribute but not in
SAXHandler for example.



More information about the jdom-interest mailing list