On Thu, 5 Feb 2004, Gary wrote:

> Tom:
> 
> Thanks for your help.
> 
> I originally added the factory creation code.  At the
> time, I didn't realize I'd need a non-static method.
> 
> The problem is that I have an abstract Factory class
> with an object creation method called something like
> newBusinessObjectInstance().  The abstract Factory
> class also has an abstract method defined called
> something like getBusinessObjectClass().  This latter
> method is implemented by the concrete factory
> subclasses (along with other methods), to let the
> abstract newBusinessObjectInstance() know what class
> to create.
> 
> Since abstract methods cannot be static, I need to get
> an instance of the concrete Factory subclass.
> 
> Clear as mud?

I can see your problem now. Initially I can think of two solutions:

1) "User-space" solution

It is likely that you use the factory as a singleton (or at least that it
could be used as one). In that case, the easiest (and most beautiful in
terms of design ;-) solution would be combination of strategy
(delegation) and singleton.
What I mean is that the factory class itself is a facade consisting of
static methods that delegate the actual creation to a singleton strategy
object (e.g. FactoryImpl) which then is a normal object (i.e. interfaces
and abstract classes can be used).

class Factory
{
    private static FactoryImpl impl = DefaultFactoryImpl();

    public static void setImpl(FactoryImpl newImpl)
    {
        impl = newImpl;
    }

    public static MyObject createMyObject()
    {
        return impl.createMyObject();
    }
}

This makes the factory implementation pluggable though the interfacing is
static (thus no moving around of the factory object is necessary).

2) "OJB" solution

Change the implementation of the factory-class stuff somewhat as you
suggested:

* retrieve the factory method object
* if the method is static, simply call it
* if not, create an object of the factory class (using
Class.newInstance) and call the method on it


Could you please have a look as to whether the first solution would work
for you ?

Tom



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to