Skip to content

Instantly share code, notes, and snippets.

@victorhtorres
Created October 11, 2021 14:21
Show Gist options
  • Save victorhtorres/b7364754ef7ea5382745067524557d2d to your computer and use it in GitHub Desktop.
Save victorhtorres/b7364754ef7ea5382745067524557d2d to your computer and use it in GitHub Desktop.
Singleton v1
# Versión Singleton más parecida a Java
class Singleton(object):
__instance = None
def __new__(cls):
if Singleton.__instance is None:
Singleton.__instance = object.__new__(cls)
return Singleton.__instance
if __name__ == '__main__':
singleton1 = Singleton()
singleton2 = Singleton()
print(singleton1 is singleton2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment