HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📝
남득윤 학습 저장소
/
디자인 패턴 (1)
디자인 패턴 (1)
/
1️⃣
Singleton Pattern
/
👍
Best Practice
👍

Best Practice

⚠️
Specific Issues

메모리 신경안써, 쓰레드 신경안써 대충 대충

→ 필드 Ver - public static final 필드 제공
 

조금 신경 좀 쓸까?

→ Bill Pugh Singleton Implementation
 

초 정석

→ Enum
public class Singleton{ public static final Singleton INSTANCE = new Singleton(); private Singleton() {} }
//inner static class 활용 class Singleton { private Singleton() {} private static class SingletonHolder { private static final Singleton INSTANCE = new Singleton(); } public static Singleton getInstance() { return SingletonHolder.Instance; } }
public enum Elvis { INSTANCE; ... }