は、私はすでに私が思っていた Creating a singleton in Pythonクラスのメソッドと属性を持つクラスは、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