如何通过调用另一个方法来绘制序列图 class

How to draw sequence diagram with a method call to another class

考虑这个class:

class Writer {
    @Inject
    private SomeAPI remove;

    public void write(Item item) {
        remove(item);
    }
}

我想为此创建一个序列图,我还想在其中表示写入方法。低于 SD 是否正确?有点糊涂了。

想了想之后,我现在像下面这样做了。请让我知道对两者的看法。

这里要考虑几个方面:

箭头描述了从一个实体到另一个实体的消息或函数调用(带有参数)以及相应的响应 messages/return 值。指向同一生命线的箭头表示同一实体内的调用或递归调用(另请参见 this helpful introduction)。

您可以使用 combined fragments. However, error handling methods such as retrying are probably a general property of your system and not specific to this sequence. In fact, many people advise against modeling exceptions 为序列中的循环或可选部分建模,以提高图表的可读性。

现在假设 Writer 的 write 方法被第三个对象调用(从你的问题中我不太清楚),图表应该如下所示: