Use Case Diagrams in Interviews: Common Questions
Use case diagrams frequently appear in LLD interviews as a requirements elicitation tool. Here are patterns, gotchas, and strategies for handling common interview scenarios.
Question 1: "Draw a use case diagram for an elevator system."
Strategy: Identify actors first (Passenger, Maintenance Staff, Emergency Services). Then list user goals (Request Floor, Open Door, Emergency Stop, Schedule Maintenance). Connect actors to use cases. Discuss whether Door Control should be separate or included in Request Floor.
Question 2: "How would you model optional features in use cases?"
Answer: Use <<extend>> relationships. Example: "Borrow Book" can be extended by "Place Hold" when the book is unavailable. The extension point is conditional: only when book.isAvailable == false. But if Y (the feature is always required like authentication), then use <<include>> instead.
Question 3: "When would you have two actors connected to the same use case?"
Answer: When multiple roles can initiate the same functionality through different interfaces. Example: In a library system, both Member (via self-service kiosk) and Librarian (via staff terminal) can initiate "Check Out Book". The use case logic is identical, but access methods differ.
First, Use case diagrams inform class identification. Each use case often maps to a service or manager class. "Park Vehicle" becomes
ParkingService.parkVehicle().Second, Actors map to user roles or external interfaces. Customer actor becomes
Customer class. Payment Gateway actor becomes IPaymentGateway interface with implementations like StripeGateway.Third, <<include>> relationships suggest composition. If "Pay Fee" includes "Process Payment", then
PaymentService composes PaymentProcessor.Fourth, <<extend>> relationships suggest strategy pattern or decorators. "Dispense Product" extended by "Apply Discount" can use a decorator chain of pricing strategies.
Mistake: Including implementation details in use case names like "Query Database for Available Spots"
Fix: Use user-goal phrasing: "Find Available Spots". The database query is implementation detail.
Mistake: Making every actor interact with every use case
Fix: Respect role-based access. Admin shouldn't connect to "Park Vehicle". Customer shouldn't connect to "Generate Report".
Mistake: Drawing use cases for internal system operations like "Update Database" or "Log Event"
Fix: Use cases represent user-visible functionality. Internal operations are implementation details, not use cases.
Mistake: Confusing actors with classes. Drawing "Vehicle" as an actor when it's actually a data entity
Fix: Actors initiate actions. Vehicle is passive data. The Customer who owns the vehicle is the actor.
Advanced Scenarios:
Temporal Actors: How do you model scheduled tasks? Create an actor called "System Timer" or "Scheduler" that initiates time-based use cases like "Generate Daily Report" or "Expire Reservations". But if Y (the scheduling is purely internal with no external trigger), then you might question whether it needs use case representation at all.
Nested System Boundaries: What if your parking lot system integrates with a payment system you also design? You can nest boundaries: outer boundary for the complete system, inner boundaries for subsystems. But if Y (this creates visual clutter), then separate diagrams for each subsystem are cleaner, showing integration points with actor relationships.
Variations and Extension Points: In complex use cases with multiple conditional paths, specify extension points with conditions. Example: "Borrow Book" has extension point [book unavailable] where "Place Hold" extends it. But if Y (you have many extension points), then the use case is too complex and should be decomposed or modeled with an activity diagram showing branching logic.
Security Use Cases: Should authentication be a use case? Yes, if users explicitly log in. Model "Authenticate User" as a use case included by other protected use cases. But if Y (authentication is transparent like session tokens), then it's an implementation detail, not a user-facing use case. However, "Reset Password" is definitely a use case because users initiate it.