DesignPattern(2)
-
싱글톤 패턴 -1- 예외 상황과 해결법
저번 게시글에서는 싱글톤 패턴에 대한 정의와 코드 구현법에 대한 이야기를 해보았다. 그런데, Java에서는 싱글톤으로 생성한 객체를 어떻게 활용하느냐에 따라, 싱글톤을 보장하지 못하는 경우가 있다고 한다. 이번 게시글에서는 싱글톤을 보장하지 못하는 경우와, 그 경우에 대한 대처법에 대해 정리해보고자 한다. 싱글톤 적용이 안되는 케이스 1 Reflection 우선 싱글톤 예제 코드를 하나 정리보도록 하자 LazyHolderSingleton public class LazyHolderSingleton implements Serializable { priate LazyHolderSingleton() {} public static class LazyHolder { private static final LazyHo..
2022.10.11 -
싱글톤 패턴 -0- 정의와 구현법
싱글톤은 디자인 패턴의 하나로, 공유자원을 여러 객체가 사용해야 하는 경우에 활용된다. 싱글톤이라는 것은 하나의 개념으로, 프로그래밍의 언어에 상관없이 구현이 가능하다. 이번 게시글에서는 Java를 기준으로 설명을 해보겠다. Singleton pattern - Wikipedia In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one "single" instance. This is useful when exactly one object is needed to coordinate actions across the system. The te..
2022.01.28