我已经阅读说明如何实现单在蟒蛇,就像 Creating a singleton in Python不是类方法和属性的类是python中的单例吗?
我想知道很多文章,是不是类方法的类和属性是一个单例类。
例如
class my_singleton_class(object):
_logger = Logger()
_printer = Printer()
@classmethod
def logger(cls):
return cls._logger
@classmethod
def printer(cls):
return cls._printer
它不是pythonic?这个单例实现有什么问题?
你应该看看这个:http://stackoverflow.com/questions/1318406/why-is-the-borg-pattern-better-than-the-singleton-pattern-in-python – phogl