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

Chapter 9: Object Behavior

Adding Transitions

A transition is a movement from one state to another. The set of transitions on a diagram shows how the object moves from one state to another. On the diagram, each transition is drawn as an arrow from the originating state to the succeeding state.

Transitions can also be reflexive. Something may happen that causes an object to transition back to the state it is currently in. For example, when we add a passenger to an open flight or remove a passenger, the flight is still open. Reflexive transitions are shown as an arrow starting and ending on the same state.

To add a transition:

1.

Select Transition from the toolbox toolbar.

2.

Click on the state where the transition begins.

3.

Drag the transition line to the state where the transition ends.

To add a reflexive transition:

1.

Select Transition to Self from the toolbox toolbar.

2.

Click on the state where the reflexive transition occurs.

OR

1.

Select Tools → Create → Transition to Self.

2.

Click on the state where the reflexive transition occurs.

To add documentation to a transition:

1.

349

Chapter 9: Object Behavior

Double−click the desired transition to open the specification window.

2.

Select the General tab.

3.

Enter documentation in the Documentation field.

Adding Transition Details

There are various specifications you can include for each transition. These include events, arguments, guard conditions, actions, and send events. Let's look at each of these, again in the context of our airline example. Figure 9.2 from earlier in this chapter shows the Statechart diagram for a Flight class.

Event

An event is something that causes a transition from one state to another to occur. In the airline example, the event Land transitions the flight from an In Flight status to a Landed status. If the flight was Delayed, it becomes Closed once the Plane Arrived event happens. An event is shown on the diagram along the transition arrow.

On the diagram, an event can be drawn using an operation name or simply using an English phrase. In the airline example, all events are given English names. If you use operations instead, the Add Passenger event might be written as AddPassenger().

Events can have arguments. For example, when removing a passenger, we will need the name of the passenger to be removed. The Remove Passenger event may therefore have an argument called PassengerName. In your Rose model, you can add arguments to your events.

Most transitions will have events—the events are what cause the transition to occur in the first place. However, you can also have an automatic transition, which has no event. With an automatic transition, an object automatically moves from one state to another as soon as all the entry actions, activities, and exit actions have occurred.

Guard Condition

A guard condition controls when a transition can or cannot occur. In the airline example, adding a passenger will move the flight from the Open to the Full state, but only if the last seat was sold. The guard condition in this example is "Last seat was sold."

A guard condition is drawn along the transition line, after the event name, and enclosed in square brackets.

350

Chapter 9: Object Behavior

Guard conditions are optional. If there is more than one automatic transition out of a state, however, there must be mutually exclusive guard conditions on each automatic transition. This will help the reader of the diagram understand which path is automatically taken.

Action

An action, as we mentioned above, is a noninterruptible behavior that occurs as part of a transition. Entry and exit actions are shown inside states, because they define what happens every time an object enters or leaves a state. Most actions, however, will be drawn along the transition line, because they won't apply every time an object enters or leaves a state.

For example, when transitioning from the Scheduled state to the Open state, we may want to initialize the number of passengers at 0. This initialization can happen while the transition is occurring, and can therefore be modeled as an action.

An action is shown along the transition line, after the event name, and preceded by a slash.

An event or action may be a behavior that occurs inside the object or a message that is sent to another object. If an event or action is sent to another object, it is preceded by a caret (^) on the diagram.

To add an event:

1.

Double−click the desired transition to open the specification window.

2.

Select the General tab.

3.

Enter the event in the Event field.

To add arguments to an event:

1.

Double−click the desired transition to open the specification window.

2.

351

Chapter 9: Object Behavior

Select the General tab.

3.

Enter the arguments in the Arguments field.

To add a guard condition:

1.

Double−click the desired transition to open the specification window.

2.

Select the Detail tab.

3.

Enter the guard condition in the Condition field.

To add an action:

1.

Double−click the desired transition to open the specification window.

2.

Select the Detail tab.

3.

Enter the action in the Action field.

To send an event:

1.

Double−click the desired transition to open the specification window.

2.

Select the Detail tab.

3.

Enter the event in the Send Event field.

4.

Enter any arguments in the Send Arguments field.

5.

Enter the target in the Send Target field.

Adding Special States

There are two special states that can be added to the diagram: the start state and the stop state.

352