Skip to content

Instantly share code, notes, and snippets.

@zmej-serow
Last active August 23, 2019 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmej-serow/f1aa765714dd4dc57116c27980a4e499 to your computer and use it in GitHub Desktop.
Save zmej-serow/f1aa765714dd4dc57116c27980a4e499 to your computer and use it in GitHub Desktop.
Singleton pattern realization via metaclass
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