본문 바로가기

개발 Note/Codes

Singleton class 설계

반응형

유용하면서 간단한 디자인패턴 : 싱글톤 패턴

 

Singleton class  Basic type

 

 

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

 

 

 

'개발 Note > Codes' 카테고리의 다른 글

[Andriod] Timer and TimerTask  (0) 2020.10.22
C++ object 관리를 위한 ObjectRef 구조 설계  (0) 2015.06.26
sorting algorithms  (0) 2014.02.26
c++ while 문 - 잘 안쓰는 표현  (0) 2013.10.23
UML2 Sementics  (0) 2012.01.11