Create a class diagram
Class diagrams are the blueprints of your system. You can use class diagrams to model the objects that make up the system, to display the relationships between the objects, and to describe what those objects do and the services they provide.
You'll design the simple phone book application using the Model-View-Controller (MVC) architecture pattern, as shown in Figure 7. (See Resources to learn about MVC.) For the phone book application you'll need to create the following three classes:
-
PhoneBookModelmanages the phone book entries and captures the state of the application. Whenever the state is changed, it notifiesPhoneBookView, which should then refresh the user interface based on the state of the application. -
PhoneBookViewmanages the graphical or textual interface to the user based on the state of the application, and notifiesPhoneBookControllerwhen an input is received. -
PhoneBookControllercontrols the operation of the entire application. It changes the model state of the application and updates the data model based on user input.
The purpose of this exercise is to show you how to use Rational Software Architect when designing an application. The design itself is not the focus. You may proceed with a different design if you prefer.
Figure 7. MVC design for the phone book application
Now create a class diagram that reflects the design in Figure 7.
- In Rational Software Architect's Model Explorer view, right-click Phone Book UML Model and select Add Diagram > Class Diagram.
- Enter
Class Diagramas the name of the generated diagram to replace the default name ClassDiagram1. - Select Class in the Palette, then click anywhere in the diagram to create a class. Name it
PhoneBookModel. - Right-click the created class PhoneBookModel and select Add UML > Operation to create an operation for this class. Name it
setState. - Similarly, create the rest of the elements as shown in Table 2. The operation names are chosen without assumptions regarding the programming language used.
| Class | Operation(s) |
|---|---|
| PhoneBookModel | addAnEntry searchPhoneNumber getSearchResult getState |
| PhoneBookView | stateHasChanged changeView getUserInput |
| PhoneBookController | userHasInput start |
- Next you'll create some associations to relate these three classes. As shown in Figure 8, click the arrow that appears next to Association from the Palette and select Directed Association.
Figure 8. Selecting Directed Association from the Palette
- Draw the association relationship line from the class
PhoneBookControllertoPhoneBookModel(the order is important) to initiate a directed association relationship between these two classes. A directed association relationship means the first class is aware of the second one, but not the other way around. - Name this directed association relationship controllerHasModel.
- Now that you've done it once, create a couple more relationships. This time create association relationships without direction, which means the two connected classes are mutually aware of each other:
- Create an association relationship between the class
PhoneBookModelandPhoneBookViewand name itmodelView. - Create an association relationship between the class
PhoneBookViewandPhoneBookControllerand name itviewController.
- Create an association relationship between the class
- The complete class diagram should look similar to Figure 9. Select Ctrl-S to save the diagram.
Figure 9. A complete class diagram for the phone book application





