Seilevel
Seilevel Home
Back to Blog Home - Requirements Defined

Wednesday, September 12, 2007

The State Machine Diagram

One of the challenges faced by requirements analysts is the need to communicate the complex behavior of systems in an understandable yet rigorous and verifiable way. A significant amount of the effort in the requirements process is devoted to translating the users’ needs and goals from ‘the language of the user’ into an actionable and unambiguous specification suitable for use as input to the design and development process. This can be a special challenge for agile teams working through relatively rapid iterations where not a lot of time is devoted to model building before coding begins.


The state machine diagram is a UML artifact that works well for this purpose. Put simply, the state machine diagram captures information about the states an object can go through during its lifecycle. Some objects have relatively simple lifecycles and for these objects the state machine diagram may be overkill. However, be careful about dismissing any object from consideration. The lifecycles of many seemingly simple objects are more complex than they may at first appear. One of the benefits of using the state machine model is that it can help illuminate requirements related to events and state transitions that may otherwise be missed.


A state machine diagram can be drawn for any object but for the purpose of documenting requirements it is often useful to look at the product as a whole or at some component of the product or of the user interface as the object whose lifecycle we are modeling. A state machine diagram can be drawn for a use case along with, or instead of, an activity diagram.


The theory behind finite state machines says that an object has a finite set of possible states it can be in. An object in a particular state can respond to certain events by making a transition to another state. During the transition an action can take place. In state theory an action is an atomic (uninterruptible) operation. A state can have an entry action and an exit action so the sequence of events for a transition would be: 1) Exit Action (from the source state). 2) Transition Action. 3) Entry Action (for the target state). According to the theory, if we have a complete list of possible states and a complete list of possible events we can develop a complete model of the lifecycle of the object. In practice, some judgment may be required to determine the appropriate level of detail depending on the purpose of the model.



To get started, think about the initial and final states of the object. Keep in mind that an object may not have a relevant final state and may simply return to its initial state or to an idle state at the completion of a cycle. Identify the states an object will go through during its lifecycle, the transitions between states, and the entry, exit, and transition actions. For complex object lifecycles it may be necessary to model substates and composite states. A substate is simply a state that is nested within another state, the composite state. A composite state can contain any number of substates and substates can be nested to any level.


As you refine the model it may be helpful to create a state transition table. The table is typically created as a matrix and for each state, shows every other state and whether a valid transition exists. Check to make sure each state, other than the initial state and final state, has at least one transition into and one out of the state. For agile and iterative processes the state machine diagrams and state transition tables can be built up and refined over time and can provide a stable model across iterations.


At completion, the model should contain a full set of the relevant states an object can exist in during its lifecycle, the events the object will react to, the transitions the object will undergo, and the actions that will occur at each entry, exit, or transition. The state machine diagram can be used to validate and enhance the user stories and use cases and can also help communicate requirements in an unambiguous way to the development team.
Requirements Defined Newsletter Bookmark and Share

3 Comments:

Blogger timhoustontx said...

First off, the statement about Finite State Machines (FSM) being a UML artifact is misleading. FSMs have been around a lot longer than UML, they are just included in UML the same way the wheel is included in automobiles...

"The theory behind finite state machines says that an object has a finite set of possible states..."

An object is not necessarilly imbued with a finite set of states from the beginning, but, rather, the state model is the side effect of a designers choices. By consciously deciding on a set of states and the conditions to transition between them, the designer has made the implementation job easier in many cases.

Modeling the real world with FSMs can be used to simply and clarify behavior, even if the real world situation doesn't exactly match a finite set of states.

9/12/2007 11:20 AM  
Anonymous Anonymous said...

Good post. I find state machine diagrams (or their structured analysis predecessors, state-transition diagrams) very useful for several aspects of requirements analysis and also design. They are excellent for representing requirements for real-time systems that can be in multiple states with only specific changes in state allowed. A good example is a highway intersection with multiple sensors, lights, crosswalks, and timers.

A state machine diagram can be used to model a user interface, where each dialog element (screen, menu, workspace, line prompt, dialog box, etc.) where the user can interact with the computer is a state and the transitions show the allowed navigation pathways from one screen to another. This is called a "dialog map."

As indicated in the original post, these diagrams are also useful for depicting the life cycle of an object that spans multiple use cases, such as a loan application. Multiple use cases could manipulate a loan application and result in a change of status, such as submitting the application, approving it (or not), withdrawing the application, and so forth. This model helps glue together information to get a bigger picture than you could learn about the object from reading any one of the use cases.

9/13/2007 8:39 AM  
Blogger Anthony C. said...

This post is being discussed at http://www.seilevel.com/messageboard/showthread.php?t=671

9/13/2007 11:40 AM  

Post a Comment

<< Home