UML状态图中的转换:更好地使用触发器或保护? [英] Transitions in UML state charts: better to use triggers or guards?

查看:385
本文介绍了UML状态图中的转换:更好地使用触发器或保护?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在UML状态图的设计中,我似乎可以选择使用触发保护逻辑来实现状态之间的转换。



那么哪个更好用呢?给定相同的逻辑转换,触发器的行为与警卫有什么不同?



根据特定的工具可能有不同,或者UML标准严格定义了两种方法的行为

解决方案



我目前使用Simulink Stateflow设计状态机。

是一个事件事件,可启用转换,
,而警戒条件,必须评估为true才能继续转换。



还要注意,默认保护(如果没有指定)是 [true],因此你不能互换使用它们 - 它们有不同的角色。 ] ,因此触发器通常足以从一个状态移动到另一个状态。



更新: >

总结:




  • 触发器是对象收到的一些新数据(任何数据类型)。

  • Guard 是某些数据的布尔表达式





触发器(事件)是一个外部事件,其他某个actor触发 - 用户按下了按钮,浏览器请求了页面加载等。所以在上面的图片中,每次用户按下数字锁上的一个数字时,它会触发按下数字事件。



如果引脚(数字序列)那么将启用到 unlocked 状态的转换。



另一种方式来看:



如果按下键盘键,系统将触发 keypress事件,这将是一个触发器,其值为按下的键。然后你可以做一个保护 [pressedKey = enter] (guard总是一个布尔表达式)。



但是在这里只有警卫是不够的,因为没有什么可以比较。


In the design of UML state charts it appears that I can chose to use either triggers or guard logic to achieve transitions between states.

So which is better to use? Given the same logic for transition, does a trigger behave any differently than a guard? What are the benefits/drawbacks of one over the other?

Are there perhaps differences depending on the particular tool, or does the UML standard strictly define the behaviors of either method of transition?

I'm presently using Simulink Stateflow to design a state machine.

解决方案

Those two are different concepts.

Trigger is an event occurrence which enables the transition, while guard is a condition that must be evaluated to true in order for the transition to proceed.

So you cannot use them interchangeably — they have different roles.

Also note that the default guard (if none is specified) is [true], so the trigger is often sufficient to move from one state to another.

Update:

Summary:

  • Trigger (event) is some new data (of any data type) that was received by the object.
  • Guard is boolean expression on some data that is alrady present in the object.

Trigger (event) is an outside event that some other actor fired - user has pressed a button, browser requested a page load, etc. So in the image above, every time user presses a digit on a digital lock it fires "pressed digit" event.

If the pin (sequence of digits) is valid, then the transition to unlocked state will be enabled.

Yet another way to look at it:

If you press a keyboard key the system fires a keypress event, that would be a trigger whose value is the pressed key. Then you can make a guard [pressedKey = enter] (guard is always a boolean expression).

However having just the guard is not enough here, because there would be nothing to compare against.

这篇关于UML状态图中的转换:更好地使用触发器或保护?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆