Singleton- oder Fabrikklasse

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
  }
}

Quelle: http://www.javaworld.com/javaworld/javatips/jw-javatip52.html

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 }}Quelle:
Noch keine Bewertungen vorhanden