Use Case Diagram
Model user interactions
Overview
Use case diagrams show the functional requirements of a system from the user's perspective. They identify actors (users or external systems) and the actions (use cases) they can perform.
While more commonly used in HLD/requirements analysis, understanding use cases helps in LLD by clarifying what the system needs to do.
Key Concepts
Actors: External entities that interact with system (stick figures)
Use Cases: Actions or goals (ovals)
System Boundary: Box containing use cases
Relationships: Association, Include, Extend
Helps identify system scope and requirements
Code Example
1/*
2Use Case Diagram for ATM System:
3
4 ATM System
5 ┌─────────────────────────────────────────┐
6 │ │
7 │ ┌─────────────────┐ │
8 │ │ Check Balance │ │
9 │ └────────┬────────┘ │
10 │ │ │
11○───┼─────────────┤ │
12│ │ │ │ │
13├─┤ │ ┌────────┴────────┐ │
14│ │ │ Withdraw Cash │──────<<include>>─┼──→ ○───○
15│ │ └────────┬────────┘ │ │ │ │
16│ │ │ │ └─┬─┘
17│ │ ┌────────┴────────┐ │ Bank
18└───┼────│ Deposit Cash │ │ System
19 │ └────────┬────────┘ │
20 │ │ │
21 │ ┌────────┴────────┐ │
22 │ │ Transfer Funds │ │
23 │ └─────────────────┘ │
24 │ │
25 │ ┌─────────────────┐ │
26 │ │ Print Receipt │ <<extend>> │
27 │ └─────────────────┘ │
28 └─────────────────────────────────────────┘
29 Customer
30
31Relationships:
32- Association: Actor ─── Use Case (actor can perform use case)
33- Include: Use Case ──<<include>>──> Use Case (always included)
34- Extend: Use Case ──<<extend>>──> Use Case (optional extension)
35
36ATM Use Cases:
371. Customer can Check Balance
382. Customer can Withdraw Cash (includes Bank verification)
393. Customer can Deposit Cash
404. Customer can Transfer Funds
415. Any transaction can extend to Print Receipt
42*/Shows ATM system use cases with actors and relationships between use cases.
Best Practices
- 1.
Focus on user goals, not implementation
- 2.
Keep use case names as verb phrases
- 3.
Don't include too many use cases (5-15 typically)
- 4.
Use include for mandatory sub-flows
- 5.
Use extend for optional features
💡 Interview Tips
Identify all actors first
Think from user perspective - what do they want to do?
Use for understanding requirements before LLD
Can help identify main classes and operations