Search code examples
umlstatediagrams

What is an order of transitions in state diagram? How to use history pseudo-states?


I read a lot about it, but still not sure in what order states executes (in Composite States) and how exactly deep and shallow history works? Could anybody help me? I have an example, which I'm not sure how to solve, here it is: enter image description here

I would appreciate any help!


Solution

  • Question 1:

    ... not sure .. how exactly deep and shallow history works?

    Answer 1:

    Note this:

    A shallow history is indicated by a small circle containing an "H". It applies to the state region that directly encloses it.

    Shallow history pseudostate represents the most recent active substate of its containing state (but not the substates of that substate). ...

    Source: http://www.uml-diagrams.org/state-machine-diagrams.html#shallow-history-pseudostate

    Question 2:

    ... I'm not sure if I always should start from initial point, which is outside of all composites?

    Answer 2:

    Yes. You start from the Initial Pseudostate of the root state (A in this case).

    Example:

    For the given state-chart and event chain, you would get the following result (simulated with Rhapsody):

    after default transition to A

    • value of x (transition to A): x = 3
    • value of x (entry A): x = x * 2 = 6
    • new state: A

    after default transition to A::B

    • new state: A::B
    • value of x: x = 6

    enter image description here

    after e1

    • value of x (entry A::C): x = x + 1 = 7
    • new state: A::C

    after default transition to A::C::G

    • value of x (entry A::C::G): x = x + 1 = 8
    • new state: A::C::G

    enter image description here

    after e3

    • value of x (exit A::C::G): x = x - 2 = 6
    • value of x (entry A::C::H): x = x / 2 = 3
    • new state: A::C::H

    enter image description here

    after e4

    • value of x (entry A::C::G): x = x + 1 = 4
    • new state: A::C::G

    enter image description here

    after e6

    • value of x (exit A::C::G): x = x - 2 = 2
    • value of x (exit A::C): x = x - 1 = 1
    • value of x (exit A): x = x - 1 = 0
    • value of x (transition to Y): x = (x * 4) + 2 = 2
    • new state: Y

    enter image description here

    after e7

    • value of x (entry A::C see the note above): x = x + 1 = 3
    • value of x (entry A::C::G): x = x + 1 = 4
    • new state: A::C::G

    enter image description here

    e4 is discarded

    enter image description here