A nested state diagram is used to model the complex system as the regular state diagram is inadequate in describing the large and complex problem. The nested state diagram is the concept of advanced state modelling.
Conventionally a complex system has much redundancy. This redundancy can be resolved by restructuring the complex system. One method to restructure complex system is to expand the state that has certain sub states.
The complex system can be restructured by implementing sub diagrams to a high-level diagram and this can be done by expanding the states that have multiple sub states. This is just like we use macros in the programming language.
To get a better understanding of this let us consider an example of a vending machine. B At the beginning the machine is idle, now, a person comes and insert some coins into the vending machine and select an item. If the selected item is not available or the amount inserted is insufficient then the machine would wait for the person to take another action.
If the amount is sufficient and the item is available then the machine would dispense the selected item and deduct the required amount from the inserted amount and would return the remaining change. The diagram below shows you the state diagram of the vending machine.
Observe the state dispense may have multiple substates so it is expanded in the lower level state diagram, which is also termed as submachine. The term submachine is defined as a state diagram which is triggered by another high-level state diagram.
In the UML notation, the sub machine is denoted by the state name followed by a colon and the corresponding submachine name. Conceptually a submachine is just like the subroutines in the programming language.
The other method to model the complex system is using nested states.
Nested states, is a deeper alternative to expanding states. When a state has multiple sub states then they could be nested and enclosed in a contour and could be labelled as the composite state name. Consider an example of a nested state for a phone line.
In the figure above, you can observe that the Active state is the composite state. The states DialTone, Dialing, BusyTone and so on all are the nested state enclosed in a composite Active state. You are allowed to nest the states to an arbitrary length. Every nested state inside the composite Active state when receives the event ‘onHook’, the corresponding state transits to the Idle state.
Let us understand nested states with one more example of ‘car transmission. Observe that there are three states inside CarTransmission state diagram i.e. reverse, neutral and forward. Among these three states, the forward state has three nested states i.e. First, Second and Third.
At any nested state of Forward gear composite state, selecting N would transit the corresponding state to the neutral state. Being in a neutral state, selecting F would transit you to the Forward state.
But here by default, the First nested state in the Forward contour is the initial state and the control is in the First state. Here the Forward is just an abstract state. You can notice that the event Stop is shared by all the three nested state. That means if the car is in any Forward gear the stopping event would transit the car to the First state.
In the nested state diagram, the entry and exit activities allow the state to indicate entry and exit without worrying about before the state is active and what happens after the state get active.
Whenever a state is transiting into a nested state or transiting out of the nested state it may be due to the execution several, entry and exit activities if the transition is occurring across several levels of the nested state. The entry activity is transiting inside the nested state and the exit activity is transiting outside the several states just like the subroutine calls in a programming language.
So, this is all about the nested state diagram which helps in modelling the complex system which the flat state diagram is unable to describe.
Leave a Reply