PlantUML画时序图
用描述性的语言来写UML,尤其是Sequence Diagram,PlantUML应该是很多同学的首选了吧。
我们可以使用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
'author Ali.Xulun
'version 1.0.0
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
显示的结果如下: