HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📝
남득윤 학습 저장소
/
객체 지향 프로그래밍
객체 지향 프로그래밍
/
디자인 패턴
디자인 패턴
/
1️⃣
Singleton Pattern
/
👍
Best Practice
👍

Best Practice

⚠️
Specific Issues

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

→ 필드 Ver - public static final 필드 제공
public class Singleton{ public static final Singleton INSTANCE = new Singleton(); private Singleton() {} }
 

조금 신경 좀 쓸까?

→ Bill Pugh Singleton Implementation
//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; } }
 

초 정석

→ Enum
public enum Elvis { INSTANCE; ... }