事件的类图UML建模

2024-06-03 17:37:30 发布

您现在位置:Python中文网/ 问答频道 /正文

python中有一个名为“事件”的模块,我们可以从中导入一个名为“事件”的对象。 URL for events module

对象可以向对象注册回调方法,其他对象可以调用事件的成员。例如,如下所示:

from events import Events

#Implementation of Events
class EventGroup(Events):
  __events__ = ('eventOne', 'eventTwo', 'eventThree')

eventGroupOne = EventGroup()


#This class subscribes to the events
class Subscriber():
  def __init__(self):
    eventGroupOne.eventOne += self.onEventOne

  def onEventOne(self):
    print("EventOne invoked")


#This class invokes the events
class Invoker():
  def someFunction(self):
    eventGroupOne.eventOne()

如何在类图UML中显示类EventGroup、Subscriber和Invoker之间的关系


Tags: the对象selfdef事件eventsthisclass
1条回答
网友
1楼 · 发布于 2024-06-03 17:37:30

如果严格遵循定义,则类图只能显示已使用的成员:

enter image description here

在这种情况下,eventOne、eventTwoeventThree仅在对象图中可见


另一种作弊的方法是考虑事件,事件2 事件3EEE>是事件组

enter image description here

相关问题 更多 >