[jdom-interest] Factories for builders.

Ken Rune Helland kenh at csc.no
Wed Mar 14 09:54:00 PST 2001

At 05:04 PM 3/14/2001 +0000, Richard Cook wrote:
>I think this will be a nice addition to JDOM capability.
>only a few very minor points
>1. is there any value in having more lightweight interfaces (eg
>ElementFactory, AttributeFactory) and JDOMFactory interface implements all
>of them. This means I can use ElementFactory wherever I need such an
>interface plugin but don't want to implement the whole JDOMFactory (though I
>don't think this is of any value within JDOM itself).

I thought about this but desided to keep to one interface to keep it simple.

If you only need to override one class you can subclass the
DefaultJDOMFactory and overide the relevant metods.

Actually I thought about making JDOMFactory a class with
behavior the same as DefaultJDOMFactory and just let
people override the metods they need, but since they
still can subclass DefaultJDOMFactory I decided on a

I also thought about making a JDOMFactory with no metods and ElementFactory 
extends JDOMFactory, AttributeFactory extends JDOMFactory and so on.
Then the setFactory metod woud look like:

public void setFactory(JDOMFactory factory)
   if( factory instanceof ElementFactory )
      elementFactory = (ElementFactory) factory

   if( factory instanceof AttributeFactory )
      attributeFactory = (AttributeFactory) factory


And you could create one factory class that implemented
one or all of the Class spesific factory interfaces.

>2. Should the factory contain only a minimal set of methods - eg
>Element(String,Namespace) rather than duplicate all constructors.

The interface woud be simpler but you woud not be able
to use the functionality already in the different constructors
so this functionality woud have to be recreated outside the factory.

Its a tradeoff, maybe the simpler interface is better.

>3. You could save a possible redundant creation of DefaultJDOMFactory by
>putting it in a lazy initialiser

Is this some java fuctionality im not aware of, or do you mean

if(factory == null) factory = new DefaultJDOMFactory()

in the beginning of the build metod?

>4. Should the doc include what it means to return null from a factory method
>(presumably not allowed?)

The doc shoud state that it must return a new created object
or must trow an (unchecked) exception.

>thanks, richard

Best regards

More information about the jdom-interest mailing list