Python裝飾器實現單例模式

# -*- coding: UTF-8 -*- # 使用裝飾器(decorator), # 這是一種更pythonic,更elegant的方法, # 單例類自己根本不知道本身是單例的,由於他自己(本身的代碼)並非單例的 def singleton(cls, *args, **kw): instances = {} def _singleton(): if cls
相關文章
相關標籤/搜索