Last active
August 23, 2019 07:46
-
-
Save zmej-serow/f1aa765714dd4dc57116c27980a4e499 to your computer and use it in GitHub Desktop.
Singleton pattern realization via metaclass
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
class Singleton(type): | |
_instances = {} | |
def __call__(cls, *args, **kwargs): | |
if cls not in cls._instances: | |
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) | |
return cls._instances[cls] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment