Creating statecharts

You can create statecharts to describe the behavior of a particular class.

The statecharts can be added only at the class level. A class can have either a statechart or an activity diagram, but not both.Statecharts define the behavior of objects by specifying how they react to events or operations. The reaction can be to perform a transition between states and possibly to execute some actions. When running in animation mode, IBM® Rational® Rhapsody® highlights the transitions between states.

To create a statechart, right‑click a class in the IBM Rational Rhapsody browser and select Add New > Diagrams > Statechart. A new (blank) diagram is displayed in the drawing area.

Note: Add New > Diagrams is the default menu command structure in the product. It can be changed by users. This topic assumes that all defaults are in place.

Statecharts define the run-time behavior of instances of a class. A state in a statechart is an abstraction of the mode in which the object finds itself. A message triggers a transition from one state to another. A message can be either an event or a triggered operation. An object can receive both kinds of messages when sent from other objects. An object can always receive events it sends to itself (self-messages). In Rational Rhapsody, statecharts are part of the object-oriented paradigm. The more complicated classes can have statecharts; simpler classes do not require them.

You can use operations and attributes in classes with statecharts to define guards and actions, as in the following example.

Statechart with guards and actions

Feedback