UML用例图设计疑问:登录功能的关联方式如何选择
Great question—this is such a common sticking point when modeling authentication flows, so let’s break it down clearly with UML best practices.
First: Link the User Actor Directly to the "Login" Use Case
First off, you absolutely should draw a direct association between your User actor and the Login use case. Why? Because users can intentionally initiate the login process on their own (think: opening your app and clicking "Log In" to gain access). This is a valid, standalone action a user can take, so it deserves its own direct link.
Second: Use include Relationships for All Core Use Cases
Now, for your core features (the ones that require a logged-in state)—like "View Personal Dashboard", "Submit a Request", or whatever your app’s main functions are—you’ll want to use the include relationship to tie them to Login.
Here’s the reasoning:
- The
includerelationship in UML means the core use case cannot complete successfully without first executing the included use case. So if a user tries to access a core feature while unauthenticated, the system will automatically trigger theLoginflow first. - If the user is already logged in (has a valid access token), the
Loginstep is just skipped—you can document this logic in the use case’s description, but the diagram will still clearly show the dependency.
A Quick Note on Preconditions vs. include
You might be thinking, "Could I just add a precondition like 'User has a valid access token' to each core use case instead?" That’s technically valid, but the include relationship makes the dependency visual at a glance. For stakeholders who might not dig into every use case’s written details, the diagram will immediately show that login is required for all core features.
Final Quick Structure Recap
- Your
Useractor connects directly to theLoginuse case (for intentional login actions) - Your
Useractor connects to each core use case - Each core use case has an
includearrow pointing to theLoginuse case (to enforce the authentication requirement)
This setup correctly frames login as a supporting (not core) use case while making it crystal clear that access to your app’s main functionality depends on it.
内容的提问来源于stack exchange,提问作者Jones

