Singleton Pattern

1.1 Definition

- Only a single instance of a class exists

1.2 Singleton instance Versus Class without instance

- Singleton class can be sub-classed -> Increase design flexibility.

- Singleton class can easily modified to allow multiple instance.

1.3 Example

public class Singleton {


 * private  static Singleton theInstance = null;


 * private Singleton {


 * }


 * public static Singleton instance {


 * if (theInstance == null)


 * theInstance = new Singleton;


 * return theInstance;


 * }

}