12.Python中的设计模式
2018-06-14 本文已影响0人
橙子只涩不酸
1.单例模式
class Dog(object):
__instance=None
def __new__(cls):
if cls.__instance==None:
cls.__instance = object.__new__(cls)
return cls.__instance
else:
return cls.__instance
a = Dog()
print(id(a))#查看实例对象指向的地址值
b = Dog()
print(id(b))