[Design Pattern] Singleton

摘要:[Design Pattern] Singleton

整個系統中對於此類別只會產生一個物件.

所有都是取用此物件

public class Singleton { 
    private static Singleton instance = null; 

    private Singleton() { 
        // .... 
    } 

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

        return instance; 
    } 

}

取得物件透過getInstance()