设计模式
sskywatcher
一个专长于网络方面的开发者,写点文章
展开
-
python中实现可继承的线程安全的单例模式
import threadingclass SingletonSample(object): _instanceLock = threading.Lock() _instance = {} def __new__(cls, *args, **kwargs): if cls not in cls._instance: print("get here 1") with cls._instanceLock...原创 2020-06-27 15:44:54 · 407 阅读 · 1 评论 -
双重检查 线程安全的python单例模式
import threadingfrom time import sleepclass SingletonSample(object): _instanceLock = threading.Lock() def __init__(self): sleep(1) @classmethod def get_instance(cls): if not hasattr(cls, "_instance"): pri.原创 2020-06-27 11:38:52 · 516 阅读 · 0 评论 -
简单工厂模式和工厂方法模式在Python中的实现
简单工厂模式class Book(object): def __init__(self,name, price): self.name = name self.price = price def read(self): print("Book name is {name}, Book's price is {price}".format(name=self.name,price=self.price))class JavaB原创 2020-06-22 23:40:22 · 282 阅读 · 0 评论