Use case diagrams are a fundamental part of the Unified Modeling Language (UML), providing a visual representation of the functional requirements of a system from the user’s perspective. This article delves into the key concepts of use case diagrams, illustrates their components through an example, and explains how base use cases, extend, and include use cases relate to use case templates and sequence diagrams.
Key Concepts of Use Case Diagrams
Actors
Actors represent users or external systems that interact with the system. They can be human users, other systems, or hardware devices. Actors are depicted as stick figures or labeled boxes outside the system boundary.
Use Cases
Use cases represent the functionalities or services provided by the system. They describe the interactions between actors and the system to achieve a specific goal. Use cases are depicted as ovals within the system boundary.
Relationships
Relationships show the interactions between actors and use cases, as well as the dependencies between use cases. The primary relationships in use case diagrams are:
- Association: A line connecting an actor to a use case, indicating that the actor participates in the use case.
- Include: A dashed arrow pointing from a base use case to an included use case, indicating that the included use case is a mandatory part of the base use case.
- Extend: A dashed arrow pointing from an extending use case to a base use case, indicating that the extending use case adds optional behavior to the base use case under certain conditions.
Example: ATM System
Let’s consider an ATM (Automated Teller Machine) system to illustrate the concepts of use case diagrams and their relationships with use case templates and sequence diagrams.
Use Case Diagram
The use case diagram for the ATM system is shown below:
Actors:
- User
Use Cases:
- Login
- Withdraw cash
- Check balance
- Donate money to charity
- Transfer money
- Pay bills
Relationships:
- The “Login” use case is a base use case that includes other use cases like “Withdraw cash,” “Check balance,” “Donate money to charity,” “Transfer money,” and “Pay bills.”
- The “Login” use case has extension points for handling invalid passwords and session timeouts.
Use Case Templates
Use case templates provide detailed documentation of each use case, including its description, actors, preconditions, postconditions, and flow of events.
Example: Use Case Template for “Login”
- Use Case Name: Login
- Actors: User
- Preconditions: The user is at the ATM.
- Postconditions: The user is logged in, or an error message is displayed.
- Flow of Events:
- The user inserts the ATM card.
- The system prompts for a password.
- The user enters the password.
- The system validates the password.
- If the password is correct, the system logs the user in.
- If the password is incorrect, the system handles the invalid password (extend).
- If the session times out, the system handles the session timeout (extend).
Extension Points:
- Invalid Password:
- Condition: The entered password is incorrect.
- Flow:
- The system displays an error message.
- The system prompts for the password again.
- Session Timeout:
- Condition: The user is inactive for a certain period.
- Flow:
- The system logs the user out.
- The system displays a timeout message.
Sequence Diagrams
Sequence diagrams model the dynamic behavior of a system by showing how objects interact over time. They focus on the order of messages exchanged between objects.
Example: Sequence Diagram for “Login”
The sequence diagram for the “Login” use case is shown below:
Objects:
- User
- ATM
- Bank System
Messages:
- The user inserts the ATM card.
- The ATM sends a request to the bank system to validate the card.
- The bank system validates the card and sends a response to the ATM.
- The ATM prompts for a password.
- The user enters the password.
- The ATM sends a request to the bank system to validate the password.
- The bank system validates the password and sends a response to the ATM.
- If the password is correct, the ATM logs the user in.
- If the password is incorrect, the ATM handles the invalid password (extend).
- If the session times out, the ATM handles the session timeout (extend).
Relationships Between Diagrams
Base Use Case and Include
The “Login” use case is a base use case that includes other use cases like “Withdraw cash,” “Check balance,” “Donate money to charity,” “Transfer money,” and “Pay bills.” This means that the user must log in before performing any of these actions. The include relationship is depicted as a dashed arrow pointing from the base use case to the included use cases.
Extend
The “Login” use case has extension points for handling invalid passwords and session timeouts. The extend relationship is depicted as a dashed arrow pointing from the extending use case to the base use case. The extending use cases add optional behavior to the base use case under certain conditions.
Use Case Templates and Sequence Diagrams
Use case templates provide a detailed description of the use case, including the flow of events. Sequence diagrams visualize the dynamic behavior of the use case by showing the interactions between objects over time. The flow of events in the use case template corresponds to the sequence of messages in the sequence diagram.
Conclusion
Use case diagrams are essential for capturing the functional requirements of a system from the user’s perspective. By understanding the key concepts of actors, use cases, and relationships, and by integrating use case diagrams with use case templates and sequence diagrams, you can effectively model the behavior of a system. The ATM system example illustrates how base use cases, extend, and include use cases relate to use case templates and sequence diagrams, providing a comprehensive view of the system’s requirements and behavior.
References
-
Sequence Diagram – Visual Paradigm
- This article explains that a sequence diagram is an interaction diagram that emphasizes the time-ordering of messages. It details how sequence diagrams depict the objects and classes involved in a scenario and the sequence of messages exchanged between them.
- Sequence Diagram – Visual Paradigm 11
-
What is Sequence Diagram?
- This guide provides an overview of sequence diagrams, explaining that they are interaction diagrams that detail how operations are carried out, including what messages are sent and when. It also discusses how sequence diagrams are organized according to time.
- What is Sequence Diagram? 12
-
How to Draw Sequence Diagram?
- This step-by-step guide shows how to create a UML sequence diagram using Visual Paradigm. It includes instructions on using the editor to construct sequence diagrams with lifelines and messages.
- How to Draw Sequence Diagram? 13
-
How to Draw UML Sequence Diagram?
- This tutorial provides a detailed walkthrough of drawing a UML sequence diagram, starting from a simple class diagram and modeling dynamic method invocations related to a controller class.
- How to Draw UML Sequence Diagram? 14
-
Sequence Diagram Tutorial – Visual Paradigm
- This tutorial explains what a sequence diagram is and provides step-by-step instructions on how to draw one. It also encourages users to create their own sequence diagrams using Visual Paradigm Online.
- Sequence Diagram Tutorial – Visual Paradigm 15
-
Sequence diagram in Visual Paradigm
- This chapter focuses on sequence diagrams in Visual Paradigm, explaining how to draw them and their primary use in showing interactions between objects in a sequential order.
- Sequence diagram in Visual Paradigm 16
-
Sequence Diagram – UML Diagrams – Visual Paradigm
- This article discusses how sequence diagrams model the collaboration of objects based on a time sequence, showing how objects interact in a particular scenario of a use case.
- Sequence Diagram – UML Diagrams – Visual Paradigm 17
-
Sequence Diagram Example – Visual Paradigm Community Circle
- This example illustrates a sequence diagram that details how operations are carried out, including what messages are sent and when. It also explains how sequence diagrams are organized according to time.
- Sequence Diagram Example – Visual Paradigm Community Circle 18
-
Using References – Visual Paradigm Community Circle
- This example shows a sequence diagram that references other sequence diagrams, such as “Balance Lookup” and “Debit Account.” It explains how the sequence starts and progresses through various interactions.
- Using References – Visual Paradigm Community Circle 19