[jdom-interest] PROPOSAL: Remove most constructors from XMLOutputter (was round trip XML)

Alex Chaffee guru at edamame.stinky.com
Wed Oct 18 09:07:58 PDT 2000


On Wed, Oct 18, 2000 at 10:16:41AM -0400, bob wrote:
> > I'd like to do this.  Can I have a straw poll on the following?
> 
> It might be completely out-of-line, but would a Configuration
> object be useful in this case?  Ever-expanding arguments
> to a Constructor definitely isn't a Good Thing in my mind.

Nonononononononono!

Sorry for the outburst, but we've been through this before.  Why do
people not seem to realize that an object *already is* its own config
object?  All an object is is a bunch of instance variables.  In
XMLOutputter's case, there are even no transient support variables --
just config options.

As for reusing settings -- That's what clone() is for!

	XMLOutputter two = (XMLOutputter)one.clone();

It works, I promise :-)

> Calling setFoo() or makeFoo() 4 times after constructing
> an object gets annoying also, if you do it repeatedly.

It's just as annoying to call setFoo() 4 times on a config object.
There's no difference between

> Howsabout:
> 
> 	XMLOutConfiguration config = new XMLOutConfiguration();
> 	config.useNewlines("true");
> 	config.stripWhitespace("true");
> 	XMLOutputter out = new XMLOutputter(config);

and 

	XMLOutputter out = new XMLOutputter();
	out.setNewline(true);
	out.setTrimText(true);

except that there's one more line of code, and one more object
allocated, and one more API to learn.

> 
> Allow folks to re-use the XMLOutConfiguration, and possibly
> initialize it from a Properties or InputStream or even
> a Document. 
> 

These are fine ideas; I'd be happy to have a 
	Properties getOptions()
	void setOptions(Properties p)
or whatever.

> Just pondering flexibility without increasing the API
> every time something new pops up.

It's a JavaBean; if it gets a new property we need to add a new
mutator.

This config object thing is a homuncular argument; it just passes the
buck.

 - A

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



More information about the jdom-interest mailing list