Monday, November 27, 2006

Creational -- Singleton


--- Singleton.java ---
package creational.singleton;

public class Singleton {

private static Singleton instance = null;

protected Singleton() {
}

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

}

OR

package creational.singleton;

public class Singleton {

private static final Singleton INSTANCE = new Singleton();

private Singleton() {
}

}

0 Comments:

Post a Comment

<< Home