싱글톤(Singletone)

class Singleton {
  private static instance: Singleton;

  private constructor() {
    // private 생성자로 외부에서 new 키워드로 인스턴스 생성을 막음
  }

  public static getInstance(): Singleton {
    if (!Singleton.instance) {
      Singleton.instance = new Singleton();
    }
    return Singleton.instance;
  }

  public someMethod(): void {
    console.log('Singleton method called');
  }
}

// 사용
const instance1 = Singleton.getInstance();
const instance2 = Singleton.getInstance();

console.log(instance1 === instance2); // true
instance1.someMethod(); // "Singleton method called"