Lesson 3: Creating a class diagram
In this lesson, you create a class diagram to specify the structure and static relationships of the classes in the system. These diagrams show the classes, objects, interfaces, and attributes in the system and the static relationships that exist between them.
Procedure
- In the Rhapsody® model browser, expand the VehicleSensor project.
- Right-click the DesignPkg package and select .
- Rename the diagram
Vehicle Sensor Overview
, then select Populate.... - In the Populate Diagram window, expand DesignPkg, then select the Sensor and Button classes.
- Click OK. The diagram is populated with the Sensor and Button classes and their associations.
- In the drawing toolbar, select the class icon and click in the drawing area.
- Place the cursor in the top panel of the class and replace
the default name with
Display
. - Right-click the Sensor class and select Add New > Attribute.
- Rename the attribute
pulse
. - Double-click
pulse
to display the Features window. - Select the General tab and set the initial value field to zero. Accept the other default values as shown:
- Right-click the Sensor class and select .
- Double-click the new operation to open the Features window.
- Select the General tab and rename
the operation
resetSensor
. - Select the Implementation tab and
type
pulse=0;
, then click OK. - Select the display class and add an operation named
show
. - In the Features window of the
show
operation, select the Arguments tab. - Add an argument named
count
of type integer. - Add the following code in the Implementation tab:
std::cout << "the pulse count is " << count << std::endl;
- Add a directed association line from Button to Sensor.
- Add composition line from Sensor to Display. Your diagram must resemble this figure:
Lesson checkpoint
In this lesson you learned how to create an object
model diagram, including:
- How to add an object model diagram in Rhapsody
- Adding functions
- Adding dependencies
- Adding implementation code
In the next lesson, you define classes behavior by creating a statechart.