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



f.vivoli@xxxxxxxxx wrote:
Hi everyone,

I've just a doubt...

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

Suppose that what createClass() method does is to instantiate a
concrete class
based on the parameter.


cheers, Francesco


You don't need an Abstract Factory to use a Singleton Pattern to get access to it, but the reason for doing so in the GoF Abstract Factory pattern, is so that we can *change* the factory that is actually returned and so we can call the createClass() method on any kind of factory.


For example, there could be some setup code that your app runs at startup, that decides which Concrete Factory to initialise the Abstract Factory with. Then the rest of the code base simply uses the AbstractFactory as you have seen, none the wiser that someone made a decision as to what the real concrete factory should be.

.



Relevant Pages

  • Re: Abstract public member variales?
    ... The relationship is instantiated in the factory and remains ... Serializable.saveItwhen using the Serializer pattern. ... Context upon any one particular algorithm of a class of related ... responsibilities of Context; ...
    (comp.object)
  • Re: Which pattern does this conform to?
    ... Andrew McDonagh wrote: ... concrete factory class; but I usually do allow the user to switch ... implementations behind the factory's interface. ... factory pattern offers the advantage that, if the user is careful, he ...
    (comp.object)
  • Re: design pattern
    ... The pattern is called Inversion of Control. ... and calls a factory to get an object instance; ... > settings and, in runtime, the factory reads settings and return the ... > -Singleton/singlecall: the returned object can be singleton or singlecall ...
    (microsoft.public.dotnet.framework)
  • Re: OO approach to decision sequence?
    ... It is a modified form of ChainOfResponsibility ... or a collection of Factory classes that all ... >> string, ... could use the COR pattern within such. ...
    (comp.lang.python)
  • Re: OO Factory(1)
    ... >> Are you essentially saying "This is how I've implemented the Factory ... Yes that is my Factory 'pattern' ... COBOL calls "FACTORY" has nothing to do with the ... If you're fighting the language, ...
    (comp.lang.cobol)