Statecharts: Limit the number of time a state gets executed

送分小仙女□ 提交于 2019-12-11 10:48:00

问题


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?

EDIT:

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

Something in this direction?

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


回答1:


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 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:

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.




回答2:


To give a graphical answer:

This is how I would model it.

The counter object is usually not needed, since it's a simple counter and it's rather obvious that the rest/increment would refer to a common counter. Also there is no real <<flow>> to that counter. A not stereotyped dependency would also suffice.



来源:https://stackoverflow.com/questions/36362570/statecharts-limit-the-number-of-time-a-state-gets-executed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!