用代码画流程图和时序图快餐教程(3) - PlantUML画时序图

本文介绍如何使用PlantUML快速绘制时序图(Sequence Diagram),包括基本语法和一个详细的示例,帮助读者理解如何定义参与者、消息传递及利用自动编号等功能。

PlantUML画时序图

用描述性的语言来写UML,尤其是Sequence Diagram,PlantUML应该是很多同学的首选了吧。

网址:
http://plantuml.com/

我们可以使用eclipse的plugin来写PlantUML,如下:
这里写图片描述

速成教程

@startuml和@enduml

这个没啥说的,开始的时候用@startuml,结束的时候要加个@enduml。

标题

格式: title 标题名

participant

格式:participant 类名 #颜色

例:

@startuml
title Android Broadcast procedure

participant Activity #Lime
participant ContextWrapper #Cyan
@enduml
消息传递

格式:类1 -> 类2 : 消息

例:

@startuml
title Android Broadcast procedure

participant Activity #Lime
participant ContextWrapper #Cyan

Activity -> ContextWrapper : registerReceiver()
@enduml
自动编号

加一句话:autonumber

例子

好了,快餐教程讲多了大家就烦了,所以基本够用的讲完了我们就看个例子吧:

@startuml
title Android Broadcast procedure
participant Activity #Lime
participant ContextWrapper #Cyan
participant ContextImpl #Cyan
participant ActivityManagerService #Cyan
participant ActivityStackSupervisor #Cyan
participant ActivityStack #Cyan
participant ApplicationThreadProxy #Silver
participant InnerReceiver #Magenta
participant ReceiverDispatcher #Magenta
participant BroadcastReceiver #Magenta

autonumber
Activity -> ContextWrapper : registerReceiver()
ContextWrapper -> ContextImpl : registerReceiver()
ContextImpl -> LoadedApk : getReceiverDispatcher()
LoadedApk -> ActivityManagerProxy : registerReceiver()
ActivityManagerProxy -> ActivityManagerService : registerReceiver()

Activity -> ContextWrapper : sendBroadcast()
ContextWrapper -> ContextImpl : sendBroadcast()
ContextImpl -> ActivityManagerService: broadcastIntent()
ActivityManagerService -> ActivityManagerService : broadcastIntentLocked()
ActivityManagerService -> ActivityManagerService : collectReceiverComponents()
ActivityManagerService -> ActivityManagerService : scheduleBroadcastsLocked()
ActivityManagerService -> ActivityManagerService : processNextBroadcast()
ActivityManagerService -> ActivityManagerService : deliverToRegisteredReceiverLocked()
ActivityManagerService -> ActivityManagerService : performReceiveLocked()
ActivityManagerService -> ApplicationThreadProxy : scheduleRegisteredReceiver()
ApplicationThreadProxy -> InnerReceiver : performReceive()
InnerReceiver -> ReceiverDispatcher : performReceive()
ReceiverDispatcher -> BroadcastReceiver : onReceive()

Activity -> ContextWrapper : sendOrderedBroadcast()
ContextWrapper -> ContextImpl : sendOrderedBroadcast()
ContextImpl -> ActivityManagerService: broadcastIntent()
@enduml

显示的结果如下:

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jtag特工

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值