싱글톤 패턴
class Singleton {
private static instance: Singleton;
private constructor() {
// 생성자 작업
}
static getInstance() {
if (!Singleton.instance) {
Singleton.instance = new Singleton();
// ... 기타 1회성 초기화 작업 ...
}
return Singleton.instance;
}
someMethod() { }
}
let something = new Singleton() // 오류: 'Singleton' 생성자는 private 임.
let instance = Singleton.getInstance() // 인스턴스를 받아서 작업 수행...Last updated