Analysis: State Machines



index
Disabled back button Next Section
printable version




Section 0: Module Objectives or Competencies
Course Objective or Competency Module Objectives or Competency
The student will be able to assess and apply Object-Oriented analysis and design methods like use cases to express user requirements, UML modeling, and other OO approaches. Understand the rules and style guidelines for behavioral state machines.
Understand the processes used to create behavioral state machines.
Be able to create behavioral state machines.
Understand the relationship between the behavioral models and the structural and functional models.


Section 1: Overview

The behavior of a use case can be described by means of activity diagrams and state diagrams, interaction diagrams (sequence and communication diagrams), as well as textual use cases, where appropriate.

Objects often pass through a variety of states over the course of their existence.

A behavioral state machine is a dynamic model that shows the different states through which a single object passes during its life in response to events, along with its responses and actions.

Typically, behavioral state machines are not used for all objects, but instead are used with complex objects to further define them and to help simplify the design of algorithms for their methods.

Behavioral state machines should be used to help understand the dynamic aspects of a single class and how its instances evolve over time, unlike interaction diagrams that show how a particular use case or use case scenario is executed over a set of classes.


Video Overview

State Diagrams

The second video on State Diagrams provides a bit more detail:



Section 2: Terminology

In order to understand state transition diagrams, we must be familiar with states, events, transitions, actions, and activities.

States

The state of an object is defined by the value of its attributes and its relationships with other objects at a particular point in time.

The attributes or properties of an object affect the state that it is in; however, not all attributes or attribute changes will make a difference.

Events

An event is something that takes place at a certain point in time and changes a value or values that describe an object, which, in turn, changes the object’s state.

Transitions

An object typically moves from one state to another based on the outcome of an action triggered by an event.

Actions

An action is an atomic, nondecomposable process that cannot be interrupted.

Activities

In contrast, an activity is a nonatomic, decomposable process that can be interrupted.



Section 3: Example 1

Try as you might, you cannot forget the Make Lunch example. Here is the sequence diagram:

Sequence diagram for Make Lunch.

And the communication diagram:

Communication diagram for Submit Order.

The following figure shows a behavioral state machine diagram for making a School Lunch:

Example of a behavioral state machine diagram.

There is obviously additional information that has been captured about the lunch object.



Section 4: Syntax
Behavioral state machine diagram syntax.

Elements of a Behavioral State Machine Diagrams

States

A state is a set of values that describes an object at a specific point in time and represents a point in an object’s life in which it satisfies some condition, performs some action, or waits for something to happen.

Arrows

Arrows are used to connect the state symbols, representing the transitions between states.

Frames

As in the other behavioral diagrams, in many cases it is useful to explicitly show the context of the behavioral state machine using a frame.



Section 5: Example 2

Recall the Make Old Patient Appointment.

The following is a behavioral state machine representing the patient class in the context of a hospital environment.

Behavioral state machine diagram for Make Appointment.


Section 6: Example 3

First we'll see the sequence diagram for submitting an order:

Sequence diagram for Submit Order.

And here is the communication diagram:

Communication diagram for Submit Order.

The following behavioral state machine deals with the life cycle of an order.

Behavioral state machine diagram for Make Appointment.

Again, there is quite a bit of additional information contained in this behavioral state machine.



Section 7: Example 4

States and subclasses can be confused.

For example, in the figure below are Freshman, Sophomore, Junior, and Senior subclasses of the class Undergraduate or are they states that an instance of the Undergraduate class goes through during its lifetime?

States vs. subclasses.

Remember, object-oriented development is iterative and incremental. As we progress to a correct model of the problem domain, we will make many mistakes.



Section 8: Guidelines for Creating Behavioral State Machines


Section 9: Creating a Behavioral State Machine

Behavioral state machines are drawn to depict an instance of a single class from a class diagram.

Here is a five-step process used to build a behavioral state machine.



Section 10 Resources