Wednesday, May 17, 2006
Anwendungsfall:
  • Es soll nur eine Instanz der Klasse existieren bzw. es soll nicht möglich sein, mehrere Instanzen der Klasse innerhalb eines Anwendungskontexts zu erzeugen.

Beispiele für die Anwendung:

  • Loadbalancer
  • ConnectionPools

Grafische Darstellung:

Beispielcode:

public class Singleton
{

   
private static Singleton instance;

   
private Singleton()
   {
   }

   public static Singleton GetInstance()
   {
      if (Singleton.instance == null)
      {
         Singleton.instance = new Singleton();
      }
      return Singleton.instance;
   }

}

Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):