State Diagrams


UML has a comprehensive notation for finite state machines. Figure 13-6 shows just the barest subset of that notation.

Figure 13-6. State machine of a subway turnstile


Figure 13-6 shows the state machine for a subway turnstile. There are two states: Locked and Unlocked. Two events may be sent to the machine. The coin event means that the user has dropped a coin into the turnstile. The pass event means that the user has passed through the turnstile.

The arrows are called transitions. They are labeled with the event that triggers the transition and the action that the transition performs. When a transition is triggered, it causes the state of the system to change.

We can translate Figure 13-6 to English as follows:

  • If we are in the Locked state and get a coin event, we TRansition to the Unlocked state and invoke the Unlock function.

  • If we are in the Unlocked state and get a pass event, we transition to the Locked state and invoke the Lock function.

  • If we are in the Unlocked state and get a coin event, we stay in the Unlocked state and call the Thankyou function.

  • If we are in the Locked state and get a pass event, we stay in the Locked state and call the Alarm function.

State diagrams are extremely useful for figuring out the way a system behaves. They give us the opportunity to explore what the system should do in unexpected cases, such as when a user deposits a coin and then deposits another coin for no good reason.




Agile Principles, Patterns, and Practices in C#
Agile Principles, Patterns, and Practices in C#
ISBN: 0131857258
EAN: 2147483647
Year: 2006
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net