Statecharts: Limit the number of time a state gets

2019-08-15 03:28发布

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]

2条回答
霸刀☆藐视天下
2楼-- · 2019-08-15 03:40

To give a graphical answer:

enter image description here

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.

查看更多
beautiful°
3楼-- · 2019-08-15 03:46

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:

enter image description here

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.

查看更多
登录 后发表回答