UML: Creating Use Case Diagrams

Contributed and maintained by Cindy Castillo, Bob May
November 2007
[Revision number: V1-4]
This publication is applicable to NetBeans IDE 6.0 release

In this tutorial, you learn how to use the UML features of the IDE to create a simple UML Use Case diagram. Using the Use Case diagram model, you show the relationship among actors and use cases within an application. The Use Case diagram that you create tracks various functions and those who interact with the functions within a theoretical banking application.

A Use Case diagram is useful when you are describing requirements for a system in the analysis, design, implementation and documentation stages. The purpose of this tutorial is to introduce the IDE's UML Use Case diagram, not to teach you about UML concepts or the Java programming language.

Expected duration: 30 minutes

Contents

  Content on this page applies to NetBeans IDE 6.0

Tutorial Requirements

Before you proceed, make sure you review the requirements in this section.

Prerequisites

To use this tutorial, the IDE must be installed on your system and you should be familiar with the basic parts of the IDE. You should also have a basic familiarity with the Java programming language and UML. For a basic understanding of the IDE, see the IDE Basics topics in the online help. A good resource for UML techniques and theory is the official UML resource page at http://www.uml.org/.

This tutorial assumes that your system meets the requirements specified in the Systems Requirements section of the NetBeans 6.0 Release Notes.

Software Needed for This Tutorial

Before you begin, download and install the following software:

top

Creating the UML Project and the Use Case Diagram

To begin this tutorial, you need to first create a UML project and a Use Case Diagram.

  1. Create a new working directory called UMLTutorial on a local partition of your system.
  2. From the main menu, choose File > New Project and then do the following in the New Project wizard:
    1. Under Categories, select UML.
    2. Under Projects, select Java-Platform Model.
    3. Click Next
      The New Java-Platform Model wizard appears.
  3. In the Project Name field, type UMLTutorialProject.
    Notice that when you type the Project Name, the IDE automatically suggests this name for the name of the Project Folder.
  4. For the Project Location field, click Browse.
  5. In the Select Project Location dialog box, select UMLTutorial, which is the directory you created in Step 1.
  6. Click Open to dismiss the dialog box.
  7. In the Name and Location page, click Finish.
    The IDE creates the UML project and the New Wizard opens and displays the Create New Diagram dialog box.
  8. In the Diagram Type list, select Use Case Diagram.
  9. In the Diagram Name field, type UseCaseDiagram.
  10. Leave UMLTutorialProject in the Namespace field and click Finish.
    The IDE does the following:

top


Adding and Labeling Use Case Elements

In this section, you add the Use Case elements using the Modeling Palette in the IDE.

  1. From the Basic section of the Modeling Palette, select the Use Case icon Use Case icon and click once in the upper left portion of the Diagram editor.

    This action places a Use Case element on the diagram.
  2. Deselect the icon by right-clicking anywhere in the Diagram editor or pressing the ESC key.
  3. If not already selected, select the newly added element by clicking on it once.
  4. Type Withdraw Money and press Enter.
    This labels the element Withdraw Money.
  5. Select the Use Case icon again and place seven more Use Case elements on the diagram. Place the elements in four rows consisting of two elements across horizontally in each row.
  6. Deselect the icon by right-clicking anywhere in the Diagram editor.
  7. Select the Use Case element located below Withdraw Money.
  8. Type Withdraw Cash from ATM and press Enter.
  9. Label the remaining Use Case elements as follows:
    Tip: As you add and label diagram elements, you can resize them as needed by right-clicking the element and selecting Resize to Element to Contents in the pop-up menu.

    The diagram should now resemble the following figure.

    Screen capture showing the Use Case diagram with labeled Use Cases

top

Adding and Labeling Actor Elements

Now, add and label the Actor elements.

  1. From the Basic section of the Modeling Palette, select the Actor icon Actor icon.
  2. Click once to the right of the Apply for a Loan Use Case element to place the Actor element in the diagram.

    An unnamed Actor element is placed in the Diagram editor.
  3. Click ESC to deselect the icon.
  4. Select the Actor element that you just placed in the diagram, type Customer and press Enter.
    The Actor element is labeled.

    Tip: As you add more diagram elements, click the Fit To Window button Fit to Window icon on the Diagram toolbar to rearrange the diagram so that you can view the entire diagram in the Diagram editor.
  5. Place five more Actor elements below the Customer Actor in the Diagram editor.
  6. Deselect the Actor icon by clicking the anywhere in the Diagram editor.
  7. Label the newly added Actor elements as follows: The diagram should resemble the following figure.

    Screen capture showing Use Case Diagram With Labeled Actors

  8. Right-click the UseCaseDiagram tab and choose Save Document from the pop-up menu.

top


Linking Actor Elements to Other Actor Elements

In this section, you link the Actor elements to each other, using the Generalization.

  1. From the Basic section of the Modeling Palette, select the Generalization iconGeneralization icon.
  2. Click the Bank Teller element, then click the Employees element.

    A link snaps into place between the two Actor elements. Information for the Generalization notation appears in the Properties window.
  3. Right-click anywhere in the diagram editor to deselect the Generalization icon.
  4. In the Diagram editor, select the Generalization link.
  5. In the Properties window, click the Stereotypes property ellipsis button (...).

    The Stereotypes wizard appears.
  6. Click Add, click then click in the blank Name field and type implementation.
  7. Click OK.

    The link is labeled <<implementation>>.
  8. Add Generalization links for the following:

    Loan Officer to Employees
    Technician to Employees

top

Linking Actor Elements to Use Case Elements

In this section, you link the Actor elements with the Use Case elements using the Associations.

  1. From the Basic section of the Modeling Palette, select the Association icon Association icon.
  2. Click Customer element and then click the Withdraw Cash From ATM Use Case element.

    A link snaps into place from the Actor to the Use Case.
  3. Right-click anywhere in the diagram editor to deselect the Association icon.
  4. With the new Association link still selected, point the cursor to the center of the line representing the link and right-click the Association link.

    Note: When the link is selected, it appears blue. It can be tricky to keep the cursor on the link. If the cursor is pointing into the white space when you right-click, you may see the pop-up menu for the Diagram editor rather than the pop-up menu for the link. Try again, making sure the link is blue, right-click and you should see the correct pop-up menu for the link as shown in the following figure.

    Screen capture showing the pop-up menu for labeling the Association link

  5. Choose Labels > Link Name from the pop-up menu.
    The link is labeled with the text Unnamed, which is highlighted.
  6. Type the text uses and press Enter.
    The link is labeled with the text uses.
  7. From the Basic section of the Modeling Palette, select the Association icon and add seven more links, connecting the Actors and Use Cases by clicking the Actor element first, and then clicking the Use Case element as follows:
  8. Deselect the Association icon.

top


Using Extend Links

An Extend link shows a relationship from one Use Case to another, specifying how the behavior defined for the extension use case can be inserted into the behavior defined for the base use case.

  1. From the Basic section of the Modeling Palette, select the Extend icon Extend icon.
  2. Click once in the Withdraw Cash From ATM element, and click again in the Withdraw Money element.

    A link labeled <<extend>> is drawn with the arrow pointing towards the Withdraw Money element.
  3. Repeat steps 1 and 2 to draw Extend links between the following Use Cases:

    Deposit Cash at ATM > Deposit Money
    Process a Loan > Apply for Loan
  4. Right-click anywhere in the Diagram editor to deselect the Extend Link icon.
  5. To rearrange the diagram, click the Orthogonal Layout button Orthogonal Style icon on the Diagram toolbar and click Yes in the Layout warning dialog box.

    Note: You may need to expand the diagram to see the Orthogonal Layout button on the toolbar. To do this, double-click the UseCaseDiagram tab. You can also right-click in the Diagram editor and choose Layout > Orthogonal from the pop-up menu. The IDE rearranges the UseCaseDiagram diagram into a rectangular layout style. Your finished diagram should resemble the following figure. Your diagram may have a slightly different layout. As long as the relationships and elements are correctly reflected, any slight difference in appearance is normal.

    Screen capture showing the completed Use Case diagram.

  6. Press Ctrl-S to save the diagram.

top

Summary

In this tutorial, you learned how to create a Use Case diagram for a simple banking application. You learned how to perform the following tasks:

top

Next Steps


Send Us Your Feedback

top

>> More NetBeans IDE Documentation