Last active
March 25, 2023 19:20
-
-
Save esilvajr/831d3c8aea5023c306963fadc1c535c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 DatabaseConnection: | |
__dbInstance = None | |
@classmethod | |
def getInstance(cls): | |
if cls.__dbInstance is None: | |
cls.__dbInstance = cls() | |
cls.__dbInstance.connect() | |
return cls.__dbInstance | |
def connect(self): | |
print("Connected to database") | |
if __name__ == "__main__": | |
print(DatabaseConnection.getInstance() == DatabaseConnection.getInstance()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment