Created
July 28, 2021 13:21
-
-
Save qmzik/167d88045ed5b5299476793e30b23892 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Класс 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