首页 > 代码库 > 类的单列模式

类的单列模式

呵呵哒....

class clss: #等于触发对象 clss() __static = None def __init__(self): pass @staticmethod def static_def(): if clss.__static: return clss.__static else: clss.__static = clss() return clss.__static def yujia(self): print(‘11‘) def youyong(self): if clss.__static: return clss.__static else: clss.__static = clss() return clss.__static def ticao(self): pass def music(self): pass w = clss.static_def() w.yujia() q = clss().youyong() print(q) q.yujia() e = clss().youyong() print(e) e.yujia()

  

类的单列模式