Search code examples
umllimitstatestatechart

Statecharts: Limit the number of time a state gets executed


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]


Solution

  • 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.