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



f.vivoli@xxxxxxxxx wrote:
Talking about factories why someone propose the way

Factory.getInstance().createClass(aType);

instead of simply

Factory.createClass(aType);

That is,
why the singleton?

Without knowing the inner details of the involved methods it is difficult to say, but very often a singleton is just used to hide a static method or a global variable, so the code looks more object-oriented. It is maybe the most common abuse of the singleton design pattern.


Should this be the case then I would suggest to drop the singleton. Why do you want to fool yourself with a singleton, if you don't need any of its features?

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

Do you want to write more code just to follow a book, or do you want to have simpler (so less error prone) code? If a GoF pattern doesn't fit, it doesn't fit, so why spend extra effort to make it fit?


/Thomas
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
.



Relevant Pages

  • Re: RMI, singletons and multiple classloaders in Weblogic
    ... With the Singleton ... >>pattern, that registry is within the class itself. ... GoF pattern: I'd nominate one of "Decorator", "Template Method", or ... "Factory / Factory Method" for that honor. ...
    (comp.lang.java.programmer)
  • Re: Singleton Pattern
    ... I have a question about singleton pattern. ... the Plant class is now coupled to LightSourceSingletonFactory and the ... LightSource interface. ...
    (comp.lang.java.programmer)
  • Re: Singleton --- almost
    ... > Singleton because only one instance is needed: ... > design patterns to apply, instead of trying to judge which design patterns are ... > pattern is relatively easy to understand, ... It may be useful to have a registry of particular objects used by ...
    (comp.lang.java.programmer)
  • Re: Creating framework for singleton pattern?
    ... >> question the usefulness, in the long run, of the Singleton pattern. ... The wiki page has a long quote from Kent Beck, ... "The Singleton Design Pattern Does More Harm Than Good" ... misused by allowing the creation of global variables in an OO context, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Singleton VS Static Class
    ... I dislike the classical version of the Singleton pattern. ... the problem had shown the need for a special instance which should be easiliy ... nothing wrong with globals if handled correctly), ...
    (comp.lang.java.programmer)