状态图:限制状态执行的时间 [英] Statecharts: Limit the number of time a state gets executed

查看:124
本文介绍了状态图:限制状态执行的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在状态图内以图形表示状态永远不会执行超过一定次数?这样它就不会以无限循环结尾.像

How can I graphically represent within Statechart Diagrams that a state never gets executed more than a certain amount of times? So that it doesn't end in an infinite loop. Something like

assert enterPIN(int p) <= 3

,如果违反条件,则分支到另一个状态.我应该以某种方式将其包括在警卫中吗?还是在国家活动中?

and then branch to another state, if condition violated. Should I include it somehow in the guard? Or in the state activities?

(CheckPIN)--[invalid]-->(counter| + inc.)--[counter>3]-->(retainCard)
    ^                      |
    |-----[counter<=3]-----|

在这个方向上发生了什么?

Something in this direction?

图例:(州名|(+-)活动),过渡:->,[后卫]

Legend: (StateName | (+-)activity), Transition: -->, [Guard]

推荐答案

我认为您的问题在杂草中太过复杂了.尽管您可以建模到最小的细节,但您应该致力于创建一个更加持久的模型,该模型将不会随着时间的推移而发生太多变化.

I think your question is way too far down in the weeds. While you can model to infinitesimal detail, you should aim to create a much more durable model that will not require as much change over time.

H.拉曼(S. Lahman)在书中使用摩尔状态机就是一个很好的例子,

H. S. Lahman makes an excellent case for using Moore state machines in his book, Model-Based Development: Applications. Moore state machines are where actions happen on entry to states, as opposed to where actions happen on transitions between states. His most compelling reason for using Moore state machines is that transitions do not degenerate into a sequence of function calls, they are instead announcements of things that have completed.

以下是如何避免所有细节并创建更耐用的模型的示例:

Here is an example of how to avoid all the detail and create a more durable model:

您会注意到,发生方式是完全封装的.例如,挑战用户可能涉及PIN码,视网膜扫描或皮下芯片.每种身份验证模式所允许的最大失败次数可能完全不同.该政策可以在其他地方代表.

You'll notice that how things happen is completely encapsulated. For example, challenging the user might involve a PIN number, retina scan, or subdermal chip. The maximum failures allowed for each of those authentication modes might be completely different. That policy can be represented elsewhere.

这篇关于状态图:限制状态执行的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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