class documentation
class Singleton(type):
Singleton metaclass.
This class implements the Singleton design pattern as a metaclass.
Attention
Classes using this metaclass will never be able to have more than one instance.
Also, instances will not be garbage collected until the program ends.
Example
- class MyClass(metaclass=Singleton):
- pass
| Method | __call__ |
Override the __call__ method to control the instantiation of classes using this metaclass. |
| Class Variable | _instances |
Dictionary to hold the single instances of the classes using this metaclass. |
Override the __call__ method to control the instantiation of classes using this metaclass.
| Parameters | |
| cls | Undocumented |
*args:Any | Positional arguments to pass to the class constructor. |
**kwargs:Any | Keyword arguments to pass to the class constructor. |
| Returns | |
object | The single instance of the class. |