Re: Is a static method sufficient to call it factory?



f.vivoli@xxxxxxxxx writes:
> Talking about factories why someone propose the way
>
> Factory.getInstance().createClass(aType);
>
> instead of simply
>
> Factory.createClass(aType);
>
> That is,
> why the singleton?
>
> In the end, is a class with a static method eligible to be an use of a
> factory method pattern? It doesn't resemble the structure of the GOF
> pattern, since it doesn't use subclassing...

The difference is that your Factory may be the implementation of some
interface. In addition, you may want to hand the Factory object to
some other class that wants to use it. In both cases you need an
instance, even if it is always the same one.

Having said that, I realise that I would probably not call a static
method that happens to return an object --- even freshly created --- a
factory.-)

Harald.

--
---------------------+---------------------------------------------
Harald Kirsch (@home)|
Java Text Crunching: http://www.ebi.ac.uk/Rebholz-srv/whatizit/software
.



Relevant Pages

  • Re: Is a static method sufficient to call it factory?
    ... Harald wrote: ... you may want to hand the Factory object to ... I admit to feel weak on the difference between calling an instance ...
    (comp.lang.java.programmer)
  • Re: why a factory class?
    ... >> This is your opportunity to use the Factory pattern. ... >> methods are sometimes called factory methods for this reason. ... > here is using the class itself as your factory object instead of having ... A separate factory class allows us to create more ...
    (comp.object)