In this lesson, you create two statecharts. Statecharts
define the behavior of actors, use cases, and classes, including the
states that they can enter over their lifetime and the events and
operations that cause them to transition from state to state. Your
statechart diagrams define the behavior for two class objects in your
model: button and sensor. They show the transitions between each state,
denoted by transition arrows.
To create the statechart for the sensor class:
- Start Rational® Rhapsody® and
open the vehicle sensor model if they are not already open.
- In the Rational Rhapsody browser,
expand the Design package, right-click the Sensor class, and
select . The Statechart element is added to the browser.
- Click
on the drawing toolbar.
- Draw a large rectangle by clicking near the upper left
corner of the drawing area and dragging to the lower right corner.
- Replace the default name with Active and
then press Enter.
- Draw two states inside the Active state and name them Idle and Sensing.
- Click the Default Transition button
and click to the left of the Idle state.
- Connect the default transition line to the Idle state.
- Click the Transition button, then click the right border
of the Idle state, and then draw a transition to
the Sensing state.
- Name the transition evToggle and then
press Ctrl+Enter.
- Draw another transition from Sensing to Idle and
name it evToggle.
- Draw another transition line from the Sensing state
back to itself.
- Double-click the transition line you drew in step 12 to
open the Features dialog box.
- Type tm(1000) in the Trigger box.
- In the Action field, press Enter and then type these two
lines of code: ++pulse; and itsDisplay.show(pulse);
- Click OK. Your diagram must resemble this figure: