Is it possible to display a return statement as the description of a transition in an UML statechart?
Is there any defined syntax or convention?
Example: int doSomething()
state 1 --- return doSomething() ---> state 2
I didn't find anything fitting on this topic and I'm not cut out to read the OMG UML specifications if it were to be written there. The only thing that I've found is this
Paper on Modelling Recursive Calls with UML State Diagrams.
The authors use Methode State Machines to track the state of a method. But I'd like to know how to write it as an action, e.g. using functions with return values rather than tracking the specific state that a method is in.
A "normal" state does not have a return. A state does not remember where it came from. However, there is a concept of State history (p. 307, current UML 2.5 specs):
The concept of State history was introduced by David Harel in the original statechart formalism. It is a convenience concept associated with Regions of composite States whereby a Region keeps track of the state configuration it was in when it was last exited. This allows easy return to that same state configuration, if desired, the next time the Region becomes active (e.g., after returning from handling an interrupt), or if there is a local Transition that returns to its history. This is achieved simply by terminating a Transition on the desired type of history Pseudostate inside the Region. The advantage provided by this facility is that it eliminates the need for users to explicitly keep track of history in cases where this type of behavior is desired, which can result in significantly simpler state machine models.
Take this for example:
When ever a transition to State1
is made, the current sub-state of State2
is saved. A transition to the little H
marked circle will restore the previous sub-state (State3
or 4
).