Singleton Pattern - MacKittipat/note-design-pattern GitHub Wiki

  • Ensure that one and only one object is instantiated for a given class
public class MySingleton {

    private static MySingleton mySingleton = null;

    private MySingleton() { }

    public static MySingleton getInstance() {
        if (mySingleton == null) {
            mySingleton = new MySingleton();
        }
        return mySingleton;
    }

}