Singleton- oder Fabrikklasse

Gespeichert von Erik Wegner am/um
public class SimpleSingleton {
  // Create the single instance, make it available statically, and
  // don't let it be redefined.

  private static final SimpleSingleton instance = new SimpleSingleton();

  // Allow subclasses to override the constructor, if necessary.

  protected SimpleSingleton() {
    // Whatever...
  // Accessor only.

  public static SimpleSingleton getInstance() {
    return instance;

  // Methods on the object to actually do something useful.
  public void doSomething() {
    // Whatever