다음은 Singleton pattern 예제 코드이다.
/**
* Singleton.java
*
* Singleton pattern의 예제
*/
package net.wiseant.designpattern.singleton;
/**
* @author Sang Hyup Lee
* @version 1.0
*
*/
public class Singleton {
private volatile static Singleton uniqueInstance;
private Singleton() {
}
public static Singleton getInstance() {
if ( uniqueInstance == null ) {
synchronized (Singleton.class) {
if ( uniqueInstance == null ) {
uniqueInstance = new Singleton();
}
}
}
return uniqueInstance;
}
}
댓글 없음:
댓글 쓰기