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

  1. In the Rhapsody® model browser, expand the VehicleSensor project.
  2. Right-click the DesignPkg package and select Add New > Diagrams > Class Diagram.
  3. Rename the diagram Vehicle Sensor Overview, then select Populate....
  4. In the Populate Diagram window, expand DesignPkg, then select the Sensor and Button classes.
  5. Click OK. The diagram is populated with the Sensor and Button classes and their associations.
  6. In the drawing toolbar, select the class Class button icon and click in the drawing area.
  7. Place the cursor in the top panel of the class and replace the default name with Display.
  8. Right-click the Sensor class and select Add New > Attribute.
  9. Rename the attributepulse.
  10. Double-click pulse to display the Features window.
  11. Select the General tab and set the initial value field to zero. Accept the other default values as shown:
    Features window for pulse attribute
  12. Right-click the Sensor class and select Add New > Operation.
  13. Double-click the new operation to open the Features window.
  14. Select the General tab and rename the operation resetSensor.
  15. Select the Implementation tab and type pulse=0;, then click OK.
  16. Select the display class and add an operation named show.
  17. In the Features window of the show operation, select the Arguments tab.
  18. Add an argument named count of type integer.
  19. Add the following code in the Implementation tab: std::cout << "the pulse count is " << count << std::endl;
  20. Add a directed association line from Button to Sensor.
  21. Add composition line from Sensor to Display. Your diagram must resemble this figure:Class diagram showing Sensor, Display, and Button classes.

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.

Related conceptsCreating object model diagramsYou can use Object model diagrams to specify the structure and the static relationships of the classes in a model. Related tasksCreating composition associationsAnother way of drawing a composite class is to use a composition association. A composition association is a strong aggregation relation connecting a composite class to a part class (component). Editing the implementation code