OO Programming in Java

Singleton


Singleton Design Pattern

Singletons are objects which have only one instance. Any class can be made into a Singleton by adding a small amount of code which insures only one instance will ever be created.

The standard way to access Singletons is:

MySingleton theSingletonObject = MySingletion.instance();

Notice that the Singleton is accessed using a Class method. This means that the Singleton can be accessed from anywhere, without a 'hook' in the Object Model.

Singleton Example