Creating a State Diagram

A State diagram is a visual representation of an application's state machines. It shows the life of an object from birth to death. In this type of diagram, you see the behavior specifying the sequence of states that the object goes through in response to events over its lifetime, and you see the object's responses to those events.

You can use a State diagram when you are working on a real-time process-control application or a subsystem that involves concurrent processing, or when you want to express the behavior of a class over several use cases.

1. Create a UML Project and add a State diagram

1. Choose File New Project.

2. In the New Project wizard:
1. Select Categories UML.
2. Select Projects Platform-Independent Model.
3. Click Next.

3. In the New Platform-Independent Model panel:
1. Type a name for the UML project, such as MyUMLProject.
2. Choose a directory where the project will be stored.

4. Click Finish.

5. In the opened New Wizard window:
1. Select State Diagram for the Diagram Type.
2. Type in a name for the diagram, such as SodaMachineStateDiagram.
3. Accept the default value for namespace.
4. Click OK.

The IDE does the following:

* Creates a platform-independent project especially designed to handle UML modeling work.
* Displays the project icon in the Project window.
* Generates a State diagram in the project.
* Displays the State diagram icons under both Project Model and Project Diagrams.
* Opens and displays the State diagram in the diagram editor.
* Opens the modeling palette to display the particular icons that are used to build State diagrams.

Next, we will draw a State diagram for a simple soda-machine application.
2. Identify State elements and add them to the State diagramHEADER

1. Add an Initial State: Click the Initial State icon in the palette, then click the upper left corner in the State diagram.
2. Add a Simple State: Click the Simple State icon in the palette, then click the State diagram to the right of the Initial State.
3. Right-click to deselect element-creation mode.
4. Double-click the Simple State and name it: Type Displaying, then press the Enter key.
5. Add three more Simple States and name them Refunding, Calculating, and Processing.
6. Add a Final State: Click the Final State icon in the palette, then click at the bottom of the State diagram.
7. Right-click to deselect element-creation mode.
8. Right-click and select Labels Final State Name to toggle the name label off. (In this particular example, the Final State does not need a name.)


3. Identify events, and connect states with State Transition

An event causes an object to transition from one state to another. In a State diagram, an event is represented by an arrow connecting the two states; this is called a State Transition element. As we continue our example, we will create a State Transition between the Initial State and the State we have called Displaying. Then, we will add several other State Transitions.

1. Add a State Transition element:
1. Click the State Transition icon in the palette.
2. Go to the State diagram and click the Initial State.
3. Click the Displaying State.

2. Add a State Transition element from the Displaying State to itself:
1. Click the State Transition icon in the palette.
2. Go to the diagram and click the Displaying State.
3. Move the mouser pointer up a bit, click the diagram, then move the pointer to the right a bit and click the Displaying State in the diagram.

3. Place a Horizontal Join/Merge element just below the Displaying State:
1. Click the Horizontal Join/Merge icon in the palette.
2. Click the State diagram below the Displaying State element.

4. Add eight more State Transition elements:
* From the Displaying State to the Horizontal Join/Merge
* From the Horizontal Join/Merge to the Refunding State
* From the Horizontal Join/Merge to the Calculating State
* From the Calculating State to the Processing State
* From the Calculating State to the Displaying State
* From the Processing State to the Refunding State
* From the Refunding State to the Final State
* From the Processing State to the Final State


4. Label State Transition with a name, and with a pre-condition or post-condition

Now we'll give the State Transition an event name and, where necessary, add a pre- or post-condition.

1. Right-click the State Transition (the linking arrow) between the Initial State and the Displaying State.
2. Choose Label Name, and type Coins Entered.
3. In the same way, label other State Transitions:

Label Name State Transition
Coins Entered Displaying State to Displaying State
Button Pressed Displaying State to Horizontal Join/Merge
Calculating Finished Calculating State to Displaying State
Calculating Finished Calculating State to Processing State
Soda Ejected Processing State to Final State
Soda Ejected Processing State to Refunding State
Coins Refunded Refunding State to Final State

Some State Transitions are subject to conditions, and these need to be labeled. A condition is shown in square brackets on the State Transition link.

1. Right-click the State Transition link between Horizontal Join/Merge and Refunding.
2. Choose Label Pre Condition, and type button=refund.
3. Repeat these steps to label pre-conditions on other State Transitions.

Pre-Condition State Transition
button!=refund Horizontal Join/Merger to Calculating State
cost<=coin value Calculating State to Processing State
cost>coin value Calculating State to Displaying State
cost cost=coin value Processing State to Final State

Comments

BhamDesigns4U said…
Sooooo where's the visual to go with this diagram?
Anonymous said…
Using BM Rational Software software this kind of UML diagrams can create

Popular posts from this blog

XSLT - Modify Date and DateTime value

Integrate With Mutual Certificate Authentication based Service

Yield Price Sri Lanka - Android Application