随笔分类 - 设计模式
摘要:观察者模式是一种行为设计模式,它允许你定义一种订阅机制,可以在对象事件发生时通知多个观察者对象。下面是一个简单的Python观察者模式代码示例: ```python class Subject: """ 被观察者类,维护观察者列表,并在状态发生改变时通知观察者 """ def __init__(se
阅读全文
摘要:Python中有多种实现单例模式的方式,以下是其中的几种: 1. 基础单例模式 ```python class Singleton(object): __instance = None def __new__(cls, *args, **kwargs): if not cls.__instance:
阅读全文

浙公网安备 33010602011771号