如何在序列图中呈现静态类或函数调用?

发布于 2025-01-01 06:09:21 字数 163 浏览 0 评论 0原文

静态类或静态函数的调用如何在序列图中呈现?根据我的理解,生命线属于类的实例/对象。 这篇文章说可以使用元类构造型。

How is a static class or call to a static function presented in Sequence Diagram? As per my understanding, the lifeline belongs to an instance/object of a class. This article says metaclass stereotype can be used.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

虫児飞 2025-01-08 06:09:21

“如有疑问,请使用注释或构造型...”

序列图:

+-------------+           +-------------------+
|  <<class>>  |           |     <<class>>     |
|     Cat     |           |  FastFoodTerminal |
+------+------+           +---------+---------+
       |                            |
       |          <<static>>        |
       |           TurnOn()         |
       +--------------------------->+---+
       |                            |   |
       +<---------------------------+<--+
       |                            |
       |       Answer   =           |
       |  DoYouHaveCheeseBurger()   |
       +--------------------------->+---+
       |                            |   |
       +<---------------------------+<--+
       |                            |

类图:

+-------------------------------------------------+
|                    <<class>>                    |
|                FastFoodTerminal                 |
+-------------------------------------------------+
| [+] void: FastFoodTerminal();   <<constructor>> |
| [#] int: ObtainMoneyDifference();               |
| [+] void: ReceiveMoney();                       |
| [+] void: ReturnChange();                       |
| [+] FastFoodTerminal: TurnOn(); <<static>>      |
+-------------------------------------------------+

在此示例中,“TurnOn()”是一个返回的静态方法,
“FastFoodTerminal”类的实例(对象)。

"In case of doubt, use comments, or stereotypes..."

Sequence Diagram:

+-------------+           +-------------------+
|  <<class>>  |           |     <<class>>     |
|     Cat     |           |  FastFoodTerminal |
+------+------+           +---------+---------+
       |                            |
       |          <<static>>        |
       |           TurnOn()         |
       +--------------------------->+---+
       |                            |   |
       +<---------------------------+<--+
       |                            |
       |       Answer   =           |
       |  DoYouHaveCheeseBurger()   |
       +--------------------------->+---+
       |                            |   |
       +<---------------------------+<--+
       |                            |

Class Diagram:

+-------------------------------------------------+
|                    <<class>>                    |
|                FastFoodTerminal                 |
+-------------------------------------------------+
| [+] void: FastFoodTerminal();   <<constructor>> |
| [#] int: ObtainMoneyDifference();               |
| [+] void: ReceiveMoney();                       |
| [+] void: ReturnChange();                       |
| [+] FastFoodTerminal: TurnOn(); <<static>>      |
+-------------------------------------------------+

In this example, the "TurnOn()" is an static method that returns,
an instance (object) of the "FastFoodTerminal" class.

岁月如刀 2025-01-08 06:09:21

所以最后是使用构造型来提到静态类/函数。下划线在 UML 2.4.1 Aug 2011 中不再适用,第 86 页,标题符号演示选项

So finally it is the use of stereotype to mention a static class/function. Underlining is no more applicable in UML 2.4.1 Aug 2011, page Page 86, under the headings Notation and Presentation Options

丢了幸福的猪 2025-01-08 06:09:21

我认为你的评论涵盖了大部分内容:

UML 2 序列图:注意对象标签如何带下划线,类和参与者没有下划线这听起来像静态类或对静态函数的调用使用相同的构造型表示,前提是 1- 模式名称的名称部分:ClassName 应该是空 2- 不应加下划线。

UML 无法完全涵盖这一点,因为静态不是 UML 定义,每种语言都有细微的差异。然而"features"[pg.1]的UML规范69](属性/操作):

isStatic:布尔值 -- 指定此功能是否表征由分类器分类的各个实例 (false) 或分类器本身 (true)。默认值为 false。

请注意,他们说的是分类器本身。所以问题是我可以将分类器放在序列图而不是实例中吗?另请注意,这并没有说分类器可以是静态的。同一 UML 规范的第 27 页显示元类“classifier”(类)中没有 isStatic。因此 UML 没有为静态类提供正式的模型功能。您可以使用构造型或关键字,或者您自己的 UML 配置文件并扩展类。但简短的答案是按照您已经发布的内容进行操作。

I think your comment covers most of it:

UML 2 Sequence Diagrams: Notice how object labels are underlined, classes and actors are not It sounds like static class or call to a static function is represented with same stereotype provided 1- the name part of the pattern name:ClassName should be empty 2- It should not be underlined.

UML cannot cover this entirely because static is not a UML definition, each language has slight variances. However the UML spec for "features"[pg. 69] (attr/operations):

isStatic: Boolean -- Specifies whether this feature characterizes individual instances classified by the classifier (false) or the classifier itself (true). Default value is false.

Notice that they say the classifier itself. So the question is can I put a classifier a sequence diagram, not an instance? Also notice that is does not say classifier can be static. Page 27 of the same UML spec shows no isStatic in the meta class "classifier" (class). So UML does not provide a formal model feature for static classes. You can use stereotype or keywords, or your own UML profile and extend Class. But the short answer is do what you already posted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文