하나의 인스턴스로 사용하는 패턴. 

글로벌 포이트로 접근이 필요한 경우에만 사용한다. 



public class Singleton { 
    private static volatile Singleton instance = null; 
    
    private Singleton() { }
    
    public static Singleton getInstance() { 
        if ( instance == null ) { 
            synchronized ( Sigleton.class) { 
                if ( instance == null ) {
                    instance = new Singleton() ; 
                } 
            }
        }
        return instance ;
    }
}

'디자인패턴' 카테고리의 다른 글

Creational pattern - Factory  (0) 2013.05.06
Posted by iRang1101
,