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 turnstileFigure 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:
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. |