UML Class Diagrams

Class Diagram Example with EA

Enterprise Architect is installed on the laptop image. However, the license key must be installed in order for the software to work. You should obtain the license key from your instructor. Then run the EA application. Follow this procedure to create your first class diagram:

  1. First, create a new project (design model file) for this lab:
    1. In the main EA window (Start Page), click on Copy a Base Project… .
    2. In the New Project field, browse to the directory where you want to create your design model, and enter “1020MSOEloginL1” (without the quotes, where MSOElogin is your MSOE login, e.g., jonesm) as the file name. The file type (.eap) will be added automatically.
    3. For now, you should leave the Model Project field at its default value (probably something like “C:\Program Files\Sparx Systems\EA\EABase.eap”). Later, you may use a special file here to configure EA in a certain way, but we don't need to do that right now.
    4. The Reset New Project GUIDs box should be checked.
    5. Click on Create Project to create your project.
  2. Your new project (1020MSOEloginL1) should now appear in the Recent Projects list in the main EA window, and the project should be openned (“1020MSOEloginL1 - EA” should now appear in the EA title bar.
  3. Next, create the top-level class diagram:
    1. If the project browser window is not visible, select Project Browser from the View menu. (If the project browser tends to disappear, you can lock it in place by clicking the “push pin” icon; to release the browser, click the icon again.)
    2. Right-click on the Model and select New View from the context menu.
    3. Enter Logical View in the Name field, select Class View and click OK.
    4. Right-click on “Logical View” and select Add → Add Diagram from the context menu.
    5. In the New Diagram dialog, enter “Lab 1 Class Diagram” in the Name field, select UML Structural for the Type and select Class in the Type list. Then, click OK.
    6. Double-click on the “Lab 1 Class Diagram” diagram icon to open the top-level class diagram. A blank diagram should open, and you should see “Lab 1 Class Diagram” on the tab at the bottom of the main window.
  4. Now, create a package for this lab:
    1. If the UML toolbox window is not visible, select Toolbox from the View menu. (Again, you can lock it in place with the “push pin” icon.)
    2. Under the Class Elements section in the Toolbox window, select Package. When you move the mouse pointer into the diagram area, it should show a plus sign to indicate that you are preparing to insert the package into the diagram. At a convenient location in the diagram window, left-click to insert the package.
    3. In the Package Name dialog, enter “lab1” (lower case and without the quotes) and click OK. The “lab1” package should appear in the diagram, and the Package dialog box should open.
    4. In the Author field, enter your last name, make sure the Language field is set to Java, and click on OK.
    5. In the Project View, you should see the “lab1” package with a “lab1” diagram below it. In the “Lab 1 Class Diagram”, double-click on the “lab1” package to open the “lab1” diagram. You should now see a “lab1” tab at the bottom of the EA window.
    6. Under the Class tab in the Toolbox window, select Class. At a convenient location in the diagram window, left-click to insert the class.
    7. In the Class dialog, enter “Circle” (without the quotes) in the Name field and enter your name in the Author field. In the Notes field, enter a short description like “This class represents a circle.”.
    8. Click on OK. The class name (“Circle”) should appear in the class symbol and the “Circle” class should appear in the Project View window.
  5. Add an attribute to the “Circle” class:
    1. Right-click on the “Circle” class symbol, and select Attributes… from the context menu. This will open the Circle Attributes dialog box.
    2. Click on New to add a new attribute. (It is not strictly necessary to do this for the first attribute, but you will need to do it for the rest.)
    3. In the Name field, enter “radius” (without the quotes).
    4. In the Type field, select double.
    5. Make sure the Scope is set to Private.
    6. In the Notes field, enter a brief description like “Radius of the circle
    7. If you wish to specify an initial value (like 0.0), enter it in the Initial field.
    8. Click on Save to add this attribute to the attribute list for the class. It should appear (selected) in the list at the bottom of the Circle Attributes dialog.
    9. Click on Close to close the Circle Attributes dialog. The “radius” attribute should now appear in the “Circle” class symbol.
  6. Add a setter operation to the “Circle” class:
    1. Right-click on the “Circle” class symbol, and select Operations… from the context menu. This will open the Circle Operations dialog box.
    2. Click New and then enter “setRadius” in the Name field. (As with the first attribute, clicking New is not necessary for the first operation.)
    3. Set the Return Type to “void” (without the quotes) and the Scope to Public.
    4. In the Notes field, enter a brief description like “Setter method for the radius attribute.”.
    5. In the Parameters field, enter “theRadius: double” to indicate the name and variable type for the parameter passed. Alternatively, you could select the Edit button to the right of the Parameters field which allows you to add multiple parameters via a dialog box.
    6. Click on Save to add this operation to the class.
    7. Click on Close to close the Circle Operations dialog. The “setRadius” operation should now appear in the “Circle” class symbol.
    8. To see the full operation specification, select Properties… from the Diagram menu and select the Features tab. In the Show Parameter Detail drop-down box, select “Full Details” and click on OK.
  7. In the Project View window, click on the plus sign next to the “Circle” class. You should see the attribute(s) and operation(s) you have created for the class.
  8. If there is an asterisk (*) next to the diagram name (“lab1”) on the tab at the bottom of the EA window, save your recent changes by selecting Save from the Diagram menu. (Many changes will be saved automatically, but some will not.)
  9. You can save the class diagram by selecting Save Image to File from the Diagram menu. Alternatively, you can copy the class diagram to the clipboard by selecting Save Image to Clipboard from the Diagram menu.

When you're done, you should have something that looks like this:

se1020labs/umlclass.txt · Last modified: 2010/03/09 20:55 (external edit)
 

This website is not owned or managed by the Milwaukee School of Engineering.

© 2003-2010 Dr. Christopher C. Taylor, et. al. • Office: L-343 • Phone: 277-7339 • npǝ˙ǝosɯ@ɹolʎɐʇ • -> RSS <-