我在Python中创建了一个单例模式,但是如果我创建了这个UML,我会在图中返回一个带有两个时间变量0121的UML。Python中的单例模式在UML中创建两个相同的变量
但我不知道为什么会发生这种情况。
#Singleton
__instance=None
def __new__(cls):
if HeatingStateOn.__instance is None:
HeatingStateOn.__instance = object.__new__(cls)
return HeatingStateOn.__instance
为什么发生这种情况,我的代码中有什么错误?
UPDATE
我运行下面的单元测试,结果显示为绿色。
def test_heatingStateOn_singleton(self):
a = HeatingStateOn()
b = HeatingStateOn()
self.assertEqual(a, b)
你能告诉我们你是如何创建类的UML的?通过什么工具或命令 –
我使用Intelij PyCharm的Diagramm功能。 –
@ michael-mammut看起来像一个bug。您应该在PyCharm的错误跟踪器中打开一个错误。 – DeepSpace