Use Case Diagrams in Visual Studio 2010

Professional Application Lifecycle Management with Visual Studio 2010 bookUse Case Diagrams

A use case diagram provides a graphical overview of the functionality of a system. It shows who is using the system and what they can do with it.

A use case diagram does not show details of use cases themselves, but instead provides a summary view of use cases, actors, and systems. Details (such as the order in which steps must be performed to accomplish the use case) can be described in other diagrams and documents, and then linked to the related use case. Use cases (and, by extension, use case diagrams) deal only with the functional requirements of a system. The architecture and any internal details are described elsewhere.

Understanding a Use Case Diagram

The best way to understand any diagram is to look at an example and take it apart. Figure 2-1 shows an example of a basic use case diagram of a customer interacting with an online bookstore system.

basic use case diagram

Figure 2-1

In Figure 2-1, you can see that a customer can view a list of books offered by the online bookstore. The customer can also order books from the online bookstore. The bookstore can also update the list of available books. Once a customer has ordered some books, the bookstore will deliver those books to the customer.

In this diagram, the objects labeled Customer and Bookstore are called actors. An actor represents a user, organization, or external system that can interact with your application. By default, the Actor object is represented by the person icon shown in Figure 2-1. However, this icon can be replaced with a different image by modifying the Image Path property of the object.

The oval-shaped objects labeled Provide Book List, Order Book, and Deliver Book are called use cases. A use case represents the actions that can be performed by one or more actors.

The lines drawn between the actors and the use cases are called associations. An association indicates that an actor can take part in a particular use case. For example, the Customer actor can view a list of books at the online bookstore.

The square box named OnlineBookstore is called a subsystem. A subsystem is the application, or part of the application, being worked on. In a particular use case diagram, a subsystem can represent the entire application, or possibly just a single class of the application. Any use cases that the subsystem supports are drawn inside the subsystem. In Figure 2-1, the Provide Book List and Order Book use cases are part of the OnlineBookstore application, so they are drawn inside the subsystem. The Deliver Book use case is outside the scope of the application, so it is drawn external to the subsystem.

Although Figure 2-1 is a very simple use case diagram, it is still very informative. You can also have more complex use case diagrams, with multiple subsystems, actors, and use cases. A best practice would be to start off describing the system with a few major use case diagrams. Each of those diagrams should define a major goal of the system. Once those goals have been defined, use some of the other objects from the use case diagram toolbox to define the system in more detail.

Let’s break the Order Book use case down in more detail. Figure 2-2 shows a use case diagram that does this by using the Include relationship.

basic use case diagram

Figure 2-2

The Include relationship shows that a use case uses all the behavior of the included use case. To differentiate it from a regular association, the Include relationship is represented as a dotted line with an arrow on the end (per the UML 2.1.2 specification). The arrow should always point to the more detailed use case. The Include relationship is also labeled with the keyword <<include>>. Each of the included use cases is a step that the actor may have to take in order to complete the main use case. In this example, in order for the customer to order a book at the online bookstore, the customer must choose a book and then pay for the book.

A use case diagram does not specify in what order the particular use cases should happen, or when a particular use case is necessary. To make that information clear, attach an Artifact object to the general use case. Do this by dropping an Artifact object onto the use case diagram, and then dragging a Dependency relationship between the Artifact element and the general use case, as shown in Figure 2-3.

basic use case diagram

Figure 2-3

An Artifact element allows you to attach a separate document to the use case (for example, a text file that describes the steps to take). Later in this chapter, you’ll learn how you can attach an activity diagram to this artifact and use case.

Use Case Diagram Toolbox

Figure 2-4 shows the different elements and associations available for use case diagrams.

Visual Studio 2010 Use Case Diagram Toolbox

Figure 2-4

Table 2-1 describes the different elements and associations.

Table 2-1: Use Case Diagram Toolbox Objects 

Turns the mouse back into a regular mouse pointer
Adds a person or external system that initiates or participates in a use case
Use Case
Adds an interaction between the system and a use case
Adds a comment for more details
Represents a part of the system
Adds a reference to a diagram or document
Links an actor with a use case
Defines how a use case requires another use case
Defines how a use case reuses another use case
Defines how a use case occurs only with another use case occurs
Defines how a use case is a specialized version of a more general use case
Comment Link
Connects a comment to a diagram element

Creating a Use Case Diagram

Let’s look at the process of creating the use case diagram shown in Figure 2-1. To get started, create a new modeling project by selecting File Ø New Ø Project to open the New Project window. Select the Modeling Project template, give the project a name and location, and click OK. A new modeling project will open in Solution Explorer. Right-click on the project in Solution Explorer, and, from the context menu, select Add Ø New Item.

Select the Use Case Diagram template and name it OrderBook.usecasediagram. Click the Add button to create this diagram. A blank use case diagram named OrderBook.usecasediagram will be created in the modeling project and opened in Visual Studio.

First, from the toolbox, drag a subsystem boundary onto the use case diagram. This subsystem can be used to represent either an entire system, or its major components. In the Properties window, change the Name property for the subsystem to be OnlineBookstore.

Next, add the actors to the use case diagram. Remember, the actors represent classes of users, organizations, and external systems that interact with the system being built. Drop two Actor objects onto the use case diagram, one on either side of the OnlineBookstore subsystem. In the Properties window, name the left actor Customer and the right actor Bookstore. The use case diagram should appear similar to Figure 2-5.

Visual Studio 2010 use case diagram

Figure 2-5

NOTE: To add multiple objects of the same type from the toolbox, double-click on the toolbox object. Then, click multiple times on the diagram to add the objects. When finished, press the Esc key to return the cursor to its regular functionality.

Once the actors are in place, drop the appropriate use cases onto the diagram. The use cases represent the activities that actors can perform. Drop two use cases inside the Online Bookstore subsystem, and rename them Provide Book List and Order Book. Add one use case outside the subsystem and name it Deliver Book.

Finally, to finish this simple use case, use the Association object to show how each actor is related to each use case. Double-click the Association object in the toolbox to select it. Click and hold on the Customer actor, and drag a line to the Provide Book List use case. An association is created between the actor and the use case. Do the same to the Order Book and Deliver Book use cases. Create associations the same way between the Bookstore actor and the Provide Book List and Deliver Book use cases.

When finished, the use case diagram should appear similar to Figure 2-1.

This article is excerpted from chapter 2 "Top-down Design with Use Case Diagrams, Activity Diagrams, and Sequence Diagrams" of the book Professional Application Lifecycle Management with Visual Studio 2010 by Mickey Gousset, Brian Keller, Ajoy Krishnamoorthy, Martin Woodward (ISBN: 978-0-470-48426-5, Wrox, 2010, Copyright Wiley Publishing Inc.)



3 responses to “Use Case Diagrams in Visual Studio 2010”

  1. Anonymous says:

    Thanks for information your article make me would like to read more use case diagrams

  2. Anonymous says:

    A very good example to show how to use Visual Studio tool
    to create a Use Case Diagram.
    Thanks a lot for your post.

  3. Creately says:

    Hey, Didn’t know that this can be done in visual studio. Thanks for the tute!

Leave a Reply to Anonymous Cancel reply

Your email address will not be published. Required fields are marked *