当前位置:网站首页>UML 时序图[通俗易懂]
UML 时序图[通俗易懂]
2022-07-04 08:56:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
概念
时序图(Sequence Diagram)描述了对象之间传递消息的时间顺序,用来表达用例中的行为顺序,是强调消息时间顺序的交互图。也就是说,时序图描述了类以及类间相互交换以完成期望行为的消息。
内容
时序图包括了 4 个元素,分别是对象(Object)、生命线(Lifeline)、激活(Activation)和消息(Message)。
- 对象(Object) 对象代表时序图中的对象在交互中所扮演的角色。时序图中对象的符号和对象图中对象所用的符号一样,都是使用矩形将对象名称包含起来,并且对象名称下有下划线,如下图所示:
将对象置于时序图的顶部意味着在交互开始的时候对象就已经存在了,如果对象的位置不在顶部,那么表示对象是在交互的过程中被创建的(对象可以在交互开始的时候创建, 也可以在交互过程中进行创建)。
- 生命线(Lifeline) 生命线是一条垂直的虚线,表示时序图中的对象在一段时间内的存在。每个对象的底部中心的位置都带有生命线。生命线是一个时间线,从时序图的顶部一直延伸到底部,所用的时间取决于交互持续的时间。对象与生命线结合在一起称为对象的生命线;对象的生命线包含矩形的对象图标以及图标下面的生命线,如下图所示:
- 激活(Activation) 时序图可以描述对象的激活(Activation)和去激活(Deactivation)。激活代表时序图中的对象执行一项操作的时期。 激活表示该对象被占用以完成某个任务,去激活指的是对象处于空闲状态,在等待消息。在UML中,为了表示对象是激活的,可以将对象的生命线拓宽成为矩形,如下图所示:
- 消息(Message) 消息是定义交互和协作中交换信息的类,用于对实体间的通信内容建模。消息用于在实体间传递信息,允许实体请求其他的服务,类角色通过发送和接收消息进行通信。它可以激发某个操作、唤起信号或导致目标对象的创建或撤销。消息序列可以用两种图来表示:时序图和协作图(时序图强调消息的时间顺序,而协作图强调交换消息的对象间的关系)。 在 UML 中,消息使用箭头来表示,箭头的类型表示了消息的类型,消息箭头指的一方是接收方,如下图所示:
时序图建模策略
(1)设置交互的语境,这些语境可以是系统、子系统、操作、类、用例和协作的一个脚本; (2)通过识别对象在交互中扮演的角色,根据对象的重要性,将其按从左向右的方向放在时序图中; (3)设置每个对象的生命线。一般情况下,对象存在于交互的整个过程,但它也可以在交互过程中被创建和撤销; (4)从引发某个交互的信息开始,在生命线之间按从上向下的顺序画出随后的消息; (5)设置对象的激活期,这可以可视化实际计算发生时的时间点、可视化消息的嵌套; (6)如果需要设置时间或空间的约束,可以为每个消息附上合适的时间和空间约束; (7)给某控制流的每个消息附上前置或后置条件,这可以更详细地说明这个控制流。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/148658.html原文链接:https://javaforall.cn
边栏推荐
- User login function: simple but difficult
- Cancel ctrl+alt+delete when starting up
- 老掉牙的 synchronized 锁优化,一次给你讲清楚!
- swatch
- Research Report on research and investment prospects of China's testing machine industry (2022 Edition)
- How college students choose suitable computers
- Ehrlich sieve + Euler sieve + interval sieve
- Call Baidu map to display the current position
- Relationship and operation of random events
- 2022 tower crane driver examination and tower crane driver examination questions and analysis
猜你喜欢

Codeforces Round #803 (Div. 2)(A-D)

What exactly is DAAS data as a service? Don't be misled by other DAAS concepts

Horizon sunrise X3 PI (I) first boot details
![C language - Introduction - Foundation - syntax - [main function, header file] (II)](/img/5a/c6a3c5cd8038d17c5b0ead2ad52764.png)
C language - Introduction - Foundation - syntax - [main function, header file] (II)

Sequence model

Call Baidu map to display the current position

Guanghetong's high-performance 4g/5g wireless module solution comprehensively promotes an efficient and low-carbon smart grid

NewH3C——ACL

Comparison between sentinel and hystrix

Codeforces Round #793 (Div. 2)(A-D)
随机推荐
C # implements a queue in which everything can be sorted
Call Baidu map to display the current position
【无标题】转发最小二乘法
Xcode 6 swift code completion does not work properly - Xcode 6 swift code completion not working
Newh3c - routing protocol (RIP, OSPF)
There are 100 people eating 100 apples, one adult eating 4 apples, and four children eating 1 apple. How can they eat exactly 100 apples? Use any high-level language you are familiar with
CLion-控制台输出中文乱码
swatch
[C Advanced] file operation (2)
L1 regularization and L2 regularization
09 softmax regression + loss function
From scratch, use Jenkins to build and publish pipeline pipeline project
How to re enable local connection when the network of laptop is disabled
Codeforces Global Round 21(A-E)
What if I forget the router password
DM8 uses different databases to archive and recover after multiple failures
如何通过antd的upload控件,将图片以文件流的形式发送给服务器
C language - Introduction - Foundation - syntax - [main function, header file] (II)
根据数字显示中文汉字
awk从入门到入土(12)awk也可以写脚本,替代shell