State Diagrams


Laurie Williams, Dright Ho, and Sarah Smith
CSC 326 - Software Engineering
Department of Computer Science
North Carolina State University

Back to Software Engineering Tutorials


0.0 Outline
1.0 Background on UML, Eclipse UML, and State Diagrams
2.0 Creating a State Diagram
3.0 Creating Objects in a State Diagram
4.0 Tips and Tricks
5.0 Exercise
6.0 Resources

1.0 Background on UML, Eclipse UML, and State Diagrams

UML

UML (Unified Modeling Language) was developed by Grady Booch, James Rumbaugh, and Ivar Jacobson, at Rational Software Corporation in 1997, for a standard way to model the structure of large applications. The UML is a standard maintained by the Object Management Group (OMG). The current version of UML is 2.0. UML provides a standardized way of modeling software, so the everyone can understand a given model. UML has several different modeling types: class diagram, sequence diagrams, state charts, and Use Cases to name a few. This tutorial will introduce programmers to creating state diagrams in Eclipse UML.

Eclipse UML

Eclipse UML is an Eclipse plug-in developed my Omondo. There is a free edition and a studio edition of Eclipse UML. The free edition will cover the modeling needs for CSC 326. You can download Eclipse UML here. After you have downloaded Eclipse UML, double click the jar file, which will then run an installer program. This will install Eclipse UML as a plug-in. We are using Eclipse UML release 2.1.0.20050718. You need to have the Eclipse Modeling Framework (EMF), Graphical Editor Framework (GEF) and UML2 Eclipse plug-ins installed. These are all Eclipse projects, and you can install them by connecting to the Eclipse update site inside of Eclipse (see Installing Plugins in Eclipse tutorial)

State Diagrams

State Diagrams are used to describe the different states and state transitions of an object in the system. State Diagrams are not able to directly translate to code, so we cannot use them in Rational XDE to generate code based on the diagram, however, State Diagrams can be useful on their own to help model the behavior of a program in order for a programmer to better understand the intricacies of the code they are writing.

The key elements of a State Diagram are, of course, the states. There are three kinds of states: initial (or start), final, and regular states where things can happen. Inside of a state there can be entry and exit conditions as well as things that are done when the object is inside the state.

To move from state to state we have transitions. Transitions can be unconditional which means that when the activities of a state are complete a transition is automatically moved to another state. There can also be events that trigger a transition. In the CoffeeMaker example, the coffee maker waits until the user inputs a command. This command would trigger a transition to a particular state.

States can also contain an internal state diagram. It can be a parallel diagram in which there are multiple states executing at once, or the diagram can just contain a single string of events with its own start and finish states. When the final state is reached the parent state is exited.

For more detailed information about State Diagrams, check out Chapter 10 in Martin Fowler's UML Distilled.

Top | Contents
2.0 Creating a State Diagram

Since state diagrams model the paths through a system, state diagrams are not tied to the code in a project.

The state diagram file is stored in the source directory or package of the associated source code. You can also create state diagrams in another folder of the project.

2.1 There are three ways to create a state diagram:

2.1.1 Select File > New > Other... > UML Diagrams > UML State Diagram,

2.1.2 Select the arrow of the button in the upper left of the toolbar. Select Other... > UML Diagrams > UML State Diagram, or

2.1.3 Right click on the source folder of package that you want to create a state diagram in and select New > Other... > UML Diagrams > UML State Diagram.

2.2 Press Next. Give the state diagram a file name. All state diagrams end in a .utd extension.

Top | Contents
3.0 Creating Objects in a State Diagram

Below are the icons on the state diagram tool bar. These are displayed at the top of the State Diagram editor window. A discussion of each of the tools is also below.

  • : Selects a component of a state diagram
  • : Zooms in on the state diagram
  • : Creates an initial state of a state diagram
  • : Creates a final state of a state diagram
  • : Creates a state
  • : Creates a history
  • : Joins two transitions together
  • : Creates a transition between two states
  • : Creates an indication between two states
  • : Creates a note
  • : Creates a link
  • : Creates a label

To add one of these components to a diagram, select the component and drag the curser from a starting point to an ending point in the editor. When you are creating an state, you will need to drag a rectangle of the size you want the state to be in the diagram. The connector icons will need to be dragged from a source object to a destination object.

Creating a State

States are allowed to have internal state information and transitions. You can create these internal transitions when you create a state in the State Diagram editor. Press the add button, and specify the event name, arguments, condition guard, and action of the transition.

Top | Contents
4.0 Tips and Tricks

4.1 If you wish to see more of your state diagram you can zoom out using the zoom feature located in the toolbar.

Top | Contents
5.0 Exercise

Import the CoffeeMaker project into your workspace. Create a state diagram in that models all of the states of the CoffeeMaker example. The CoffeeMaker requirements can be found here.

Show your state diagram to your TA for credit.

Top | Contents
6.0 Resources
Top | Contents

Back to Software Engineering Tutorials


State Diagrams in Eclipse Tutorial ©2003-2005 North Carolina State University, Laurie Williams, Dright Ho, Sarah Smith
Email Sarah Smith with any questions or comments about this tutorial.
Last Updated: Tuesday, September 20, 2005 2:57 PM