[英]Describe transition of a class in UML's Statechart Diagram
I read that Statechart Diagram is generally used to describe transition of an object. 我读到Statechart Diagram通常用于描述对象的转换。 One of those objects is a class.
这些对象之一是类。
Could you give me an instance of how to generate statechart diagram showing transition of a class in OOP programming? 您能否给我一个实例,该实例如何生成状态图,以显示OOP编程中类的转换?
I've googled it before, but found nothing. 我以前用Google搜索过,但是什么也没找到。 The part where I'm a bit confused is where to put functions and attributes of a class in statechart diagram.
我有点困惑的是在状态图图中将类的函数和属性放在哪里。
Thanks in advance! 提前致谢!
Attributes/operations are part of the transitions. 属性/操作是过渡的一部分。 You can check attributes as part of a Guard which limits transition between states.
您可以将属性作为Guard的一部分进行检查,以限制状态之间的转换。 On Entry/Exit (and inside) of a state you can perform operations of the class.
在状态的进入/退出(以及内部)中,您可以执行类的操作。
Edit based on your comment: 根据您的评论进行编辑:
Suppose I have a class called Teacher
with two functions named getteachername()
and setteachername()
with one attribute named name
. 假设我有一个名为
Teacher
的类,它具有两个名为getteachername()
和setteachername()
函数,并且具有一个名为name
属性。
You would use a state chart (in the following very trivial and silly case) if you need to implement constraints. 如果需要实现约束,则可以使用状态图(在以下非常琐碎和愚蠢的情况下)。 Say that the name can only be set on a rule that allows to append a string to it if it starts with "Paul".
假设只能在允许以“ Paul”开头的字符串上附加字符串的规则上设置名称。 Then you start with the state
isEmpty
. 然后从状态
isEmpty
开始。 It has an outgoing transition modify
where it goes to statePaul
if the name is set to "Paul". 如果名称设置为“ Paul”,则它将
statePaul
进行传出过渡modify
。 From that state you can transit to the same state when appending something to name
. 在
name
附加一些内容后,您可以从该状态转换为相同状态。 From the stateOther
you can only transit to the isEmpty
. 从
stateOther
只能转移到isEmpty
。
Note that this is constructed, silly and non-realistic. 请注意,这是构造的,愚蠢的和不现实的。 But it shows how a state machine controls changes of attributes based on using methods of a class.
但是它显示了状态机如何基于使用类的方法来控制属性的更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.