Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
9
Task/Singleton/Python/singleton-3.py
Normal file
9
Task/Singleton/Python/singleton-3.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
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]
|
||||
|
||||
class Logger(object):
|
||||
__metaclass__ = Singleton
|
||||
2
Task/Singleton/Python/singleton-4.py
Normal file
2
Task/Singleton/Python/singleton-4.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
class Logger(metaclass=Singleton):
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue