With IBM® Rational® Software Architect RealTime Edition,
you can create models using passive classes, rather than capsules,
and then generate the corresponding code. The behavior of the passive
classes is represented by state machines. This type of modeling is
often referred to as state-machine code generation.
Before you begin
Not all applications require the power of encapsulated active
objects, and not all objects in an application must be capsules. You
can create a model by using passive classes, and then add state machines
to the classes to generate state machine functions and state variables.
Triggers on the transitions between states are the operations for
the passive classes.
The code for the state machine is contained
entirely in the passive class and does not depend on external classes
or the runtime systems. From an external perspective, classes with
state machines on them are no different than classes with operations.
The state machines support all the runtime semantics of classes in
a capsule-based model and can generate the corresponding code.
Unlike
capsules, passive classes for state machines do not have redefinition
support; however, passive classes can inherit operations and attributes
from superclasses. Trigger operations cannot be inherited, but they
can call other operations from the superclasses.
You can add
code directly to the model as operations and attributes. If you modify
a passive class state machine, you can regenerate the state logic
without losing detailed code annotations, such as transitions, entry
and exit actions, and guards.
The following task outlines how
to create a passive class model and transform the model to code. For
more detailed information about these steps, see the Related links
at the end of the topic.
About this task
To create a model with passive classes and generate the corresponding
code:
Procedure
- Create a passive class model:
- Create a new model by using the UML Capsule
C++ Development Model template. As the
following diagram illustrates, a class diagram, called Main, is automatically
created and opens in the diagram editor, and a default transformation
configuration is created.
- Add a class to the class diagram.
- In the diagram editor, right-click the class; then click Open
State Machine Diagram. A state machine,
and the corresponding state machine diagram, are automatically created
for the class, and the state machine diagram opens in the diagram
editor.
- In the state machine diagram, add an initial state and
an initial transition.
- Add required states and transitions.
- Add required triggers to the transitions.
- In the Code view, add the necessary
behavior code to states, transitions, and triggers.
- Save the model.
- Revise the transformation configuration:
- In the Project Explorer view,
double-click the default transformation configuration. The
transformation configuration opens in a separate editor.
- In the transformation configuration editor, click the Properties tab.
- From the Environment list, select C++.
- Optional: Specify other properties as required.
- Save the updates.
What to do next
You can now run the transformation configuration, build the
UML development model project, and compile the code for the passive
class model.