【PlantUML】- 时序图

写在前面

  本篇文章,我们来介绍一下PlantUML的时序图。这个相对类图来讲,比较简单,也不需要布局。读完文章,相信你就能实际操作了。


目录


一、基本概念

时序图,是我们梳理复杂系统交互或设计的一大法宝。概念不多解释,直接上示例。


二、具体步骤

1.环境说明

名称 说明
Windows Windows10
Intellij IDEA版本 Intellij IDEA 2019.2.3(Ultimate Edition)
PlantUML Integration IDEA插件 2.23.0

2.元素

以下为PlantUML脚本,

uml 复制代码
@startuml
title 时序图的元素

participant ac << (A,#A8DEDF) AbstractClass >>
participant interface << (I,#B4A7E3) Interface >>
participant class << (C,#ADD1B2) Class >>

participant Participant as P
participant "()非字母形式" as P2

actor       Actor       as A #red
boundary    Boundary    as B #blue
control     Control     as C
database    Database    as D
entity      Entity      as E order 3
collections Collections as C2 order 2
queue       Queue       as Q order 1
@enduml

效果,

3.语法

以下为PlantUML脚本,

uml 复制代码
@startuml
skinparam style strictuml
skinparam sequenceArrowThickness 2
skinparam roundcorner 20
skinparam sequenceParticipant underline
autoactivate on

title 时序图语法
actor User

participant "First Class" as A
note over A: 这是对First Class的注释

participant "Second Class" as B
note over B: 这是对Second Class的注释

participant "third Class" as C
note across: 这是跨越所有\n参与者的注释

participant "Last Class" as D
hnote across: 这是跨越所有\n参与者的注释


== 第一段逻辑 ==
A -> B: A请求B
note right
    这是对A->B请求的注释
end note

B -> C: B请求C
C -> C: C请求自身
return success

C --> B: C响应B

== 第二段逻辑 ==
B -> D: B请求D
D -> D: D请求自身
return success

D --> A: D响应A

@enduml

效果,

4.示例

以下为PlantUML脚本,

uml 复制代码
@startuml
skinparam style strictuml
autoactivate on
autonumber

title 时序图示例

==阶段1==
autonumber 1
Alice -> Bob: request
'Bob --> Alice:  Response
return response

==阶段2==
autonumber 1

alt 场景1
    Alice -> Bob: request
    Alice <-- Bob: response
end

alt#Gold #LightBlue 场景2
autonumber 1
    Alice -> Bob: request

else 场景2.1
    Alice <-- Bob: response
    Alice -> Bob: request
    Alice <-- Bob: response
'    return response

else #Pink 场景2.2
    loop 1000次
        Alice -> Bob: request
        return response
    end
end

group 自定义
autonumber
    Alice -> Bob: request
    Alice <-- Bob: response
end

@enduml

效果,

最后,分享以下个人比较喜欢的几种颜色,用于标识重要节点或流程。

复制代码
#Lime, #Cyan, #Silver, #Magenta, #EEE, #FFBBBB, #DarkSalmon

至此,你就可以开启时序图的征程了~


三、参考资料

PlantUML 序列图


写在后面

  如果本文内容对您有价值或者有启发的话,欢迎点赞、关注、评论和转发。您的反馈和陪伴将促进我们共同进步和成长。


系列文章

【PlantUML】-类图
【PlantUML】-布局
【IDEA插件】- PlantUML integration-Can't find Graphviz

相关推荐
rolt4 天前
智能机床-06 机械 ISO 23704-4-2026-用UML表示的行业标准
软件工程·产品经理·架构师·uml
rolt7 天前
05 医学 ISO 13940-用UML表示的行业标准,健康信息学 — 支持照护连续性的概念体系
软件工程·架构师·uml
rolt7 天前
3GPP-5G-用UML表示的行业标准-04电信移动通信
软件工程·ddd·uml·ontology
Warren2Lynch9 天前
掌握 UML 用例建模:地图与路线的完美结合
uml
rolt10 天前
OGC CityGML-用UML表示的行业标准03地理
软件工程·uml·ontology·本体
微小冷22 天前
用Mermaid画时序图
运维·流程图·时序图·mermaid·生命线
自传.24 天前
B 站更新|软考架构师案例篇・软件工程篇第 2-4 集上线|UML 用例图|类图|顺序图真题精讲
架构·系统架构·软考高级·uml·案例分析·用例图·软考系统架构师
码匠许师傅1 个月前
【设计模式精讲】29.行为型模式总结与对比(Behavioral Patterns Summary)
c++·设计模式·uml
码匠许师傅1 个月前
【设计模式精讲】27.模板方法模式(Template Method)
c++·设计模式·uml·模板方法模式
码匠许师傅1 个月前
【设计模式精讲】26.策略模式(Strategy)
c++·设计模式·策略模式·uml