class Single(object):
def __new__(cls, *args, **kwargs):
if not hasattr(cls, '_instance'):
cls._instance = super(Single, cls).__new__(cls, *args, **kwargs)
return cls._instance
class A(Single):
pass
def single2(cls):
_instance = {}
def wapper(*args, **kwargs):
if cls not in _instance:
_instance[cls] = cls(*args, **kwargs)
return _instance[cls]
return wapper
@single2
class B(object):
pass
网友评论