如何在序列图中显示多个循环并在其中执行操作?

发布于 2024-09-27 02:29:59 字数 124 浏览 4 评论 0原文

我想展示当我在其中插入数据列表时我的用户控件/控件正在做什么,当用户按下某些键、选择文本等时会发生什么...

我觉得序列图并不适合显示多个循环并在循环中做一些事情。

我错了吗?或者我该如何应对这种情况?

I want to show what my UserControl/Control is doing when I plug a list of data in it, what happens when the user press certain keys, selecting text etc...

I feel somehow a sequence diagramm is not really suited for showing several loops and doing stuff within the loops.

Am I wrong or how can I cope with that case?

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

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

发布评论

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

评论(1

执妄 2024-10-04 02:29:59

如果您谈论的是循环,那么循环中的所有元素都会发生一系列操作。

如果循环中的操作相当复杂,我会将循环中完成的操作建模为序列图。

我不认为我们在这里可以有经验法则,但是当循环本身的过程很复杂,并且循环相对不太复杂时,我们可以将它们放在单个序列图中。

如果有循环的进程不是很复杂,但是循环很复杂,那么我会为循环的操作绘制一个序列图,并注明整个序列是由循环调用的。

如果需要,您还可以同时拥有两个序列图。

更新:
我们必须在图中添加一些注释,因为在序列图中表示“条件”并不简单。
验证部分类似于

do validation
if validation succeeds
   proceed to next (business or other) logic
if validation fails
   feedback to user (or some other logic)

+----+          +----+          +----------------+      +----------------+
|User|          | UI |          | Your Validator |      | Business Logic |
+----+          +----+          +----------------+      +----------------+
  |     select     |                   |                        |
  |--------------->|   doValidation    |                        |
  |                |------------------>|----+                   |
  |                |                   |    | Validate          |
  |                |                   |<---+                   |
  |                |                   |                        |
  |                |                   | (validation fails:     |
  |                |  Validation Fail  |  feedback to client)   |
  |                |<------------------|                        |
  |                |                   |                        |
  |                |                   |                        |
  |                |                   | (validation succeeds:  |
  |                |                   |  proceed to            |
  |                |                   |  business logic)       |
  |                |                   |                        |          
  |                |                   |    someLogic           |
  |                |                   |----------------------->|
  |                |                   |                        |

UPDATE 2
为什么在我这样的案例中使用序列图?
因为您仍然必须显示操作的顺序,并且开发人员仍然需要这些信息来进行编码:-)

正如您可能已经知道的那样,对于 UML,没有什么是强加的。您可以自由地以某种方式表示某些内容,只要您的团队也按照您想要的方式理解它。这些注释也很有帮助。

我之前应该提到过这一点,有些人使用“选项”片段来表示 if else。这或多或少是一个注释(我是这样看的),但也许更明显。仅当 IFELSE 部分都很复杂时,我才使用它们。

    +----+          +----+          +----------------+      +----------------+ 
    |User|          | UI |          | UI - Backend   |      |  Busines Logic |
    +----+          +----+          +----------------+      +----------------+
      |  Add Record    |                   |                        |
      |--------------->|  doinsertOrUpdate |                        |
      |                |------------------>|                        |
      |                |                   |      exists(record)    |
      |                |                   |----------------------->|
      |                |                   |                        |         
  ____|________________|___________________|________________________|__________
  |[Record exists]     |                   |                        |         |
  |   |                |                   |     Get Record         |         |
  |   |                |                   |----------------------->|         |
  |   |                |                   |                        |         |
  |   |                |                   |--------+               |         |
  |   |                |                   |        | Set UI Values |         |
  |   |                |                   |<-------+               |         |
  |   |                |                   |                        |         |
  |   |                |                   |   Update Record        |         |
  |   |                |                   |----------------------->|         |
  |   |                |                   |                        |         |
  |   |                | Send Message      |                        |         |
  |   |                |<------------------|                        |         |
  |   |                |  "Record found,   |                        |         |
  |   |                |   Updated"        |                        |         |
  |___|________________|___________________|________________________|_________|
      |                |                   |                        |
      |                |                   |                        |
______|________________|___________________|________________________|_________
| [Record does not     |                   |                        |         |
| exist]               |                   |                        |         |
|     |                |                   |--------+               |         |
|     |                |                   |        | Generate      |         |
|     |                |                   |        | Seqeuence     |         |
|     |                |                   |<-------+               |         |
|     |                |                   |                        |         |
|     |                |                   |   Create New Record    |         |
|     |                |                   |----------------------->|         |        
|     |                | Send Message      |                        |         |
|     |                |<------------------|                        |         |
|     |                |  "New Record      |                        |         |
|     |                |   Created"        |                        |         |
|_____|________________|___________________|________________________|_________|
      |                |                   |                        |
      |                |                   |                        |
      |                |                   |                        |

有关使用 alt 块的示例,请参阅

If you are talking about a loop, then you have a series of operations that take place for all elements in the loop.

I would model the operations done in the loop as a sequence diagram by itself, if the operation in the loop are fairly complex.

I don't think we can have rules of thumb here, but when the process with the loop itself is complex, and the loop is relatively less complex, we can have them in a single sequence diagram.

If the process that has the loop is not very complex, but the loop is complex, then I would draw a sequence diagram for the operations of the loop and have a note that this entire sequence is called by a loop.

You can also have both sequence diagrams if needed.

Update:
We have to add some notes to the diagram because it is not straightforward to denote a "condition" in a sequence diagram.
The validate is part is something like

do validation
if validation succeeds
   proceed to next (business or other) logic
if validation fails
   feedback to user (or some other logic)

+----+          +----+          +----------------+      +----------------+
|User|          | UI |          | Your Validator |      | Business Logic |
+----+          +----+          +----------------+      +----------------+
  |     select     |                   |                        |
  |--------------->|   doValidation    |                        |
  |                |------------------>|----+                   |
  |                |                   |    | Validate          |
  |                |                   |<---+                   |
  |                |                   |                        |
  |                |                   | (validation fails:     |
  |                |  Validation Fail  |  feedback to client)   |
  |                |<------------------|                        |
  |                |                   |                        |
  |                |                   |                        |
  |                |                   | (validation succeeds:  |
  |                |                   |  proceed to            |
  |                |                   |  business logic)       |
  |                |                   |                        |          
  |                |                   |    someLogic           |
  |                |                   |----------------------->|
  |                |                   |                        |

UPDATE 2
Why use sequence diagram in a case as mine?
Because you still have to show the sequence of operations, and the developer still needs this information for coding :-)

With UML, as you probably already know, nothing is imposed. You are at your freedom to denote something in some fashion, provided your team also understands it the way you intended. These notes are also helpful.

I should have mentioned this before, some use an "option" fragment to denote a if else. This is more or less a note (I see it this way) but is perhaps more evident. I use them only when both the IF and the ELSE parts are both complex.

    +----+          +----+          +----------------+      +----------------+ 
    |User|          | UI |          | UI - Backend   |      |  Busines Logic |
    +----+          +----+          +----------------+      +----------------+
      |  Add Record    |                   |                        |
      |--------------->|  doinsertOrUpdate |                        |
      |                |------------------>|                        |
      |                |                   |      exists(record)    |
      |                |                   |----------------------->|
      |                |                   |                        |         
  ____|________________|___________________|________________________|__________
  |[Record exists]     |                   |                        |         |
  |   |                |                   |     Get Record         |         |
  |   |                |                   |----------------------->|         |
  |   |                |                   |                        |         |
  |   |                |                   |--------+               |         |
  |   |                |                   |        | Set UI Values |         |
  |   |                |                   |<-------+               |         |
  |   |                |                   |                        |         |
  |   |                |                   |   Update Record        |         |
  |   |                |                   |----------------------->|         |
  |   |                |                   |                        |         |
  |   |                | Send Message      |                        |         |
  |   |                |<------------------|                        |         |
  |   |                |  "Record found,   |                        |         |
  |   |                |   Updated"        |                        |         |
  |___|________________|___________________|________________________|_________|
      |                |                   |                        |
      |                |                   |                        |
______|________________|___________________|________________________|_________
| [Record does not     |                   |                        |         |
| exist]               |                   |                        |         |
|     |                |                   |--------+               |         |
|     |                |                   |        | Generate      |         |
|     |                |                   |        | Seqeuence     |         |
|     |                |                   |<-------+               |         |
|     |                |                   |                        |         |
|     |                |                   |   Create New Record    |         |
|     |                |                   |----------------------->|         |        
|     |                | Send Message      |                        |         |
|     |                |<------------------|                        |         |
|     |                |  "New Record      |                        |         |
|     |                |   Created"        |                        |         |
|_____|________________|___________________|________________________|_________|
      |                |                   |                        |
      |                |                   |                        |
      |                |                   |                        |

See this for an example using an alt block.

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