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

Chapter 9: Object Behavior

The second is to use state history to remember where the object was. If the History option is set, an object can leave a superstate and then return and pick up right where it left off. The History option is shown with a small "H" in a circle at the corner of the diagram, as shown in Figure 9.6.

Figure 9.6: Superstate history

To nest a state:

1.

Select State from the toolbox.

2.

Click on the state in which to nest the new state.

To use state history:

1.

Open the specification window for the desired state.

2.

Select the General tab.

3.

Select the State/Activity History check box.

4.

If you have states within states within states, you can apply the history feature to all nested states within the superstate. To do so, select the Substate/Activity History check box.

Exercise

In this exercise, we will create a Statechart diagram for the Product class.

Problem Statement

In designing the Product class, Karen realized that it was a class that may require special attention. Many of the requirements varied significantly as the state of a product changed. For example, products that were backordered could not be purchased.

355

Chapter 9: Object Behavior

To be sure the design was sound, she sat down with the other developers in the group and worked out a Statechart diagram for the class. With this information, the developers had a very good sense of what it was going to take to code the class.

Create a Statechart Diagram

Create the Statechart diagram shown in Figure 9.7 for the Order class.

Figure 9.7: Statechart diagram for the Product class

Exercise Steps:

Create the Diagram

1.

Locate the Product class in the browser.

2.

Right−click the class and select New Statechart Diagram.

Add the Start and Stop States

1.

Select Start State from the toolbox.

2.

Place the state on the diagram.

3.

Select End State from the toolbox.

4.

Place the state on the diagram.

356

Chapter 9: Object Behavior

Add the States

1.

Select State from the toolbox.

2.

Place the state on the diagram.

3.

Name the state Ordered.

4.

Select State from the toolbox.

5.

Place the state on the diagram.

6.

Name the state Inventoried.

7.

Select State from the toolbox.

8.

Name the state Out of Stock.

9.

Select State from the toolbox.

10.

Name the state Selected for Purchase.

11.

Select State from the toolbox.

12.

Place the state on the diagram.

13.

Name the state Purchased.

Add Transitions

1.

Select Transition from the toolbox.

2.

Click the Start State.

3.

Drag the transition line to the Ordered state.

4.

357

Chapter 9: Object Behavior

Repeat steps 1–3 to add the following transitions:

Ordered to Out of Stock

Ordered to Inventoried

Inventoried to Selected for Purchase

Selected for Purchase to Inventoried

Selected for Purchase to Purchased

Purchased to End State

Out of Stock to End State

Inventoried to End State

Add Transition Details

1.

Double−click the Ordered to Out of Stock transition to open the specification.

2.

Select the Detail tab.

3.

In the Guard Condition field, enter backordered.

4.

Click OK to close the specification.

5.

Repeat steps 1–4 to add the guard conditions to the following transitions:

[received] between Ordered and Inventoried

[in shopping cart] between Inventoried and Selected for Purchase

[paid] between Selected for Purchase and Purchased

358