I am trying to model a GUI app with statecharts, the basic logic is:
-
We have a initial composite state
S
, and when states transitioning fromS1
toS4
,timeout
orerror
events could occurs, which will make the state machine transition into anAlert
state, which will display an alert dialog. -
I make
S
an composite state so that the edges to and fromAlert
will be minimized. -
The user can either choose to
retry
when the app inAlert
state, or close the app, or just doing nothing and waiting for timeout. -
But among
S3
andS4
are "transient" states, which means if error occurs in theses states, if the user choose toretry
, we can only restart fromS2
, rather thanS3
orS4
. I make a composite stateS5
and use the history mechanism to implmenet this feature.
This approach doesn't scale, say, what if we have more nested states inside S1
or S2
, and some of them are transient(non recoverable), the hierarchy will go deeper and deeper and the whole statecharts will become messy. Are there any best practices for this kind of modeling?
Plantuml code for the diagram:
@startuml demo
hide empty description
[*] --> S
state Alert
state S {
[*] --> S1
S1 --> S5
state S5 {
[*] --> S2
S2 --> S3
S3 --> S4
}
Alert --> [H]: retry
}
S --> Alert: timeout or error
Alert --> [*]: timeout or quit
@enduml
Aucun commentaire:
Enregistrer un commentaire