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

Actually, one of the reasons to use a singleton is that the getInstance method can return a subclass. So some subclassing is really used, which makes it more similar to a factory method.
Looks a bit strange implementation, though. The singleton should always return the same instance, whereas the factory patterns are made to work with more subclasses.
.




Relevant Pages

  • Re: Singleton - Whether Cloneable overrides Singleton
    ... [snip example of a Singleton class which is Cloneable] ... Making it Cloneable breaks this pattern - now you have a non-singleton with ... Have another factory method ... Singleton with patterns that create multiple instances. ...
    (comp.lang.java.programmer)
  • Re: Singleton - Whether Cloneable overrides Singleton
    ... [snip example of a Singleton class which is Cloneable] ... Making it Cloneable breaks this pattern - now you have a non-singleton with ... Have another factory method ... Singleton with patterns that create multiple instances. ...
    (comp.lang.java.programmer)
  • Re: Is this a kind of design patterns?
    ... who cares if it's pattern #1 or pattern #2. ... Betreff: Re: Is this a kind of design patterns? ... But the definition of "Factory Method Pattern" bothered me. ... "Define an interface for creating an object, but let subclasses decide ...
    (comp.lang.ruby)
  • Re: Observer Design Pattern
    ... Design Patterns are not the kind of thing that you can turn into a reusable coding library. ... require 'singleton' ... I'm not familiar with Ruby, so I'm curious about the above code. ... singletons would have a static factory method ") to make themselves useful. ...
    (comp.object)
  • Re: Singleton with Factory Method possible?
    ... > Is it possible to combine the Singleton and Factory Method design ... > virtual function from a static function: ...
    (comp.lang.cpp)