Skip to content

Instantly share code, notes, and snippets.

@qmzik
Created July 28, 2021 13:21
Show Gist options
  • Save qmzik/167d88045ed5b5299476793e30b23892 to your computer and use it in GitHub Desktop.
Save qmzik/167d88045ed5b5299476793e30b23892 to your computer and use it in GitHub Desktop.
/**
* Класс Singleton предоставляет метод getInstance, который позволяет клиентам
* получить доступ к уникальному экземпляру одиночки.
*/
class Singleton {
private static instance: Singleton;
/**
* Конструктор Singleton должен быть приватный, чтобы кто-нибудь случайно не создал
* объект через оператор new.
*/
private constructor() {}
/**
* Статический метод, управляющий доступом к экземпляру одиночки.
*/
public static getInstance(): Singleton {
if (!Singleton.instance) {
Singleton.instance = new Singleton();
}
return Singleton.instance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment