摘要: 1、通过闭包函数实现单例模式: # 使用闭包函数实现单例 def single(cls, *args, **kwargs): instance = {} def get_instance(): if cls not in instance: instance[cls] = cls(*args, ** 阅读全文
posted @ 2020-01-06 20:39 奔奔-武 阅读(428) 评论(0) 推荐(0) 编辑
摘要: model = input("请选择模块:") class_ = input("请选择类型:") money = input("请输入金额:") # 导入模块 model = __import__(model) # 实例化对象 object = getattr(model, class_)(mone 阅读全文
posted @ 2020-01-06 20:31 奔奔-武 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 工厂方法实现放在factory_method.py模块中: class BenBen: def __init__(self, money): """ 奔奔支付 :param money:支付金额 """ self.money = money def pay(self): print("收到奔奔金融支 阅读全文
posted @ 2020-01-06 20:19 奔奔-武 阅读(347) 评论(0) 推荐(0) 编辑
摘要: 1 class BenBen: 2 def __init__(self, money): 3 """ 4 奔奔金融支付 5 :param money:支付金额 6 """ 7 self.money = money 8 9 def pay(self): 10 print("收到奔奔金融支付金额{0}" 阅读全文
posted @ 2020-01-06 20:04 奔奔-武 阅读(390) 评论(0) 推荐(0) 编辑