[5장] Singleton Pattern
Singleton Pattern클래스 인스턴스를 하나만 만들고, 그 인스턴스로의 전역 접근을 제공한다.구현 기법1) Lazy initializationpublic class Singleton { private static Singleton uniqueinstance; // 하나뿐인 인스턴스를 저장하는 정적 변수 private Singleton() {} // 생성자를 private로 선언 public static Singleton getInstance() { // 클래스 인스턴스를 하나만 생성 if(uniqueInstance == null) { // 인스턴스가 생성되지 않았을 때 uniqueInstance = new Singleton(); // 객체 생성 ..
- Books/Head First Design Pattern
- · 2024. 5. 24.