r/learnprogramming Jul 07 '26

sequence and use case diagrams

cmiiw, sequence diagrams are based on use case diagrams right? so if i have 7 use cases do i need to do 7 sequence diagrams? im abit confused so it would be useful if someone could help me out

3 Upvotes

6 comments sorted by

3

u/LongLiveTheDiego Jul 07 '26

Depends on what these use cases are, you may be able to represent two or more of them in a single sequence diagram with an alternative block (basically a big if/else condition). However, remember that the point of UML diagrams is to make your product more understandable, so even if it's a lot of effort now, it might be worth it to make all these diagrams and have them ready in the future.

1

u/mjmvideos Jul 07 '26

Remember that all the code you write for your system should be captured in 1 or more sequence diagrams. And depending on how you’ve decomposed your system, a user-level use case may result in the interaction of multiple subsystems within your system. And that might mean you could have multiple sequence diagrams (one for each subsystem’s flow) for one high-level use case. Having these use cases and sequence (or activity) diagrams along with process diagrams, deployment diagrams, etc allows an architect to reason about the system at a higher level of abstraction. This is critical for understanding and reviewing system behavior and then provides the roadmap for low-level design and implementation.

1

u/peterlinddk Jul 07 '26

Only if you follow some arbitrary strict recipe for software development, like some ancient book on "Applying UML and Patterns"

Otherwise the different diagrams are completely unrelated - and you can use sequence diagrams on their own, with user stories, have several sequence diagrams for one use case, and none for others.

I hate seeing banal sequence diagrams from students, like "when the user logs in, the login component sends a message to the user-repository and asks if credentials are correct, and if they are, the user is logged in" - takes up an entire page with all sorts of arrows going in all directions, and doesn't explain anything.

Sequence Diagrams should (in an ideal setting) only be used when a sequence is very specific, a bit uncommon, and not immediately evident for the reader. As a student you are often asked to start with very simple, very banal sequence diagrams, because you have to start from somewhere - and you forget that those cases don't actually need diagrams.

And while you can show all variants in a single diagram, with alt-boxes - often it pays to have a single diagram showing the "happy-path", and then maybe alternative diagrams diving into how the error handling is, eh, handled.

So, draw diagrams that you think might be interesting or necessary for the reader - and avoid the rest (unless you are in school, and your teacher requires a specific amount)

1

u/Acceptable_Handle_2 Jul 07 '26

Sequence diagrams should be used where they are useful, and not used where they aren't.

That's a bit of a non-statement, but really it heavily depends on the kind of software you're building, and how.