摘要: """ 享元模式 将不可变(可共享)的属性与可变的属性分开 """ import random from enum import Enum TreeType = Enum('TreeType', 'apple_tree cherry_tree peach_tree') class Tree: poo 阅读全文
posted @ 2022-02-24 15:53 fly_bk 阅读(54) 评论(0) 推荐(0) 编辑
摘要: """ 修饰器模式 """ import functools def memoize(fn): known = dict() @functools.wraps(fn) def memoizer(*args): if args not in known: known[args] = fn(*args) 阅读全文
posted @ 2022-02-24 14:01 fly_bk 阅读(42) 评论(0) 推荐(0) 编辑