relationship of Factory method and singleton design patterns?

From: Matt (jrefactors_at_hotmail.com)
Date: 11/29/04


Date: 29 Nov 2004 07:28:20 -0800

what's the differences between factory method and singleton? and
relationships?

In the following code, Factory method getInstance() is to create new
objects like constructors.
class SingleInstance is a singleton class because it has exactly one
instance. A singleton
class has factory method getInstance(). Looks like a singleton class
always has
factory methods? Or a factory method is used in a singleton class.

public class SingleInstance
{
   public static SingleInstance getInstance()
   { ...
     return singleInstance;
   }

   private static SingleInstance singleInstance = new
SingleInstance();
   ...
}

Please discuss and advise. thanks!!



Relevant Pages