개발
[디자인패턴] Singleton
madison
2022. 8. 4. 12:13
싱글턴 (Singleton)
A Singleton only allows for a single instantiation, but many instances of the same object. The Singleton restricts clients from creating multiple objects, after the first object created, it will return instances of itself.
인스턴스가 하나만 생성되는것을 보장하고 해당 인스턴스에 글로벌하게 접근할수 있는 패턴을 뜻합니다.
- 하나의 인스턴스만 생성
- 어디서나 접근 가능한 클래스 메서드
- 클래스 메서드를 통해 모든 클라이언트에게 동일한 인스턴스를 제공
사용하는 인스턴스를 하나만 생성하여 관리의 집중화를 통해 유지보수 비용을 줄이고 높은 신뢰성을 부여할 수 있습니다.
실무에서는 전역 상태를 사용하기 위한 entry point 를 제공하는 형태로 패턴을 사용할 수 있습니다.
레퍼런스 : https://www.freecodecamp.org/news/singleton-design-pattern-with-javascript/
실전 타입스크립트 디자인 패턴 (개정판)