Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Mastering UML with Rational Rose 2002.pdf
Скачиваний:
137
Добавлен:
02.05.2014
Размер:
9.68 Mб
Скачать

Chapter 9: Object Behavior

Start State

The start state is the state the object is in when it is first created. In the airline example, a flight begins in the Tentative state. A start state is shown on the diagram as a filled circle.

A transition is drawn from the circle to the initial state.

A start state is mandatory: the reader of the diagram will need to know what state a new object is in. There can be only one start state on the diagram.

To add a start state:

1.

Select Start State from the toolbox toolbar.

2.

Click on the Statechart diagram where the start state should appear.

Stop State

The stop state is the state an object is in when it is destroyed. A stop state is shown on the diagram as a bull's−eye.

Stop states are optional, and you can add as many stop states as you need.

To add a stop state:

1.

Select End State from the toolbox toolbar.

2.

Click on the Statechart diagram where the stop state should appear.

Using Nested States and State History

To reduce clutter on your diagram, or as a design decision, you can nest one or more states inside another. The nested states are referred to as substates, while the larger state is referred to as a superstate.

If two or more states have an identical transition, they can be grouped together into a superstate. Then, rather than maintaining two identical transitions (one for each state), the transition can be moved to the superstate. Figure 9.4 is a portion of our Statechart diagram for the Flight class. As you can see, the flight moves into the Closed state 10 minutes before takeoff, regardless of whether it was in the Open or Full state before.

353

Chapter 9: Object Behavior

Figure 9.4: Statechart diagram without nested states

To reduce the number of arrows on the diagram, we can create a superstate around Open and Full, and then just model a single transition to the Closed state. Figure 9.5 is the same portion of the diagram with nested states. (As you can see, superstates can help to reduce the clutter on a Statechart diagram.)

Figure 9.5: Statechart diagram with nested states

At times, you may need the system to remember which state it was last in. If you have three states in a superstate and then leave the superstate, you may want the system to remember where you left off inside the superstate. In our example, if we want to temporarily suspend reservations while the system is undergoing routine maintenance, we may transition to a SuspendReservations state while the maintenance is occurring. Once the maintenance is done, we want to return to whatever state the flight was in before the maintenance started.

There are two things you can do to resolve this issue. The first is to add a start state inside the superstate. The start state will indicate where the default starting point is in the superstate. The first time the object enters that superstate, this is where the object will be.

354