The singleton pattern is a software design pattern that restricts the instantiation of a class to a singular instance.
Using metaclass
In Python, there are multiple ways to do that but the most effective is using metaclasses.
In the example above, the Logger class is a singleton - every instance of the Logger will be the same. There will always be only one Logger and all Logger objects will refer to that one Logger.
Got an article suggestion?
Let us know
BY
NC
SA
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.