问题
I'm trying to design UML Analysis Class Diagram for a college project. My UML Diagram looks like this:
I have encountered two different problems:
- User can have multiple roles. A user with Manager role can manage other users and their roles. How to illustrate this association in UML?
- User uses SwipeCard to access a room. How to show this association in UML?
回答1:
You have a really good start to an analysis model. Some things I would do:
- Reify the association between
User
andRole
(or make it an association class) calledRole Assignment
. - Add a verb-phrased property name to every end of every association. For example,
Manager
authorizesRole Assignment
andRole Assignment
authorized byManager
.
Here's an example first cut, off the top of my head:
I left off a bunch of stuff, including operations, which I would suppress for validation with SMEs. I can't do all the work for you! 😉
回答2:
Short Quick Answer
Make the Role
class, not the Manager
class.
Long Boring Answer
I had a similar case, but, eventually, had a similar Manager
class, and later add a MiddleManager
class that could also manage other classes.
..........................
..+-----------------+.....
..| User |--+..
..+-----------------+..|..
...........^...........|..
........../ \..........|..
..........\ /..........|..
...........v...........|..Can Manage Other Users
...........|...........|..
...........|...........|..
...........|...........|..
..+-----------------+..|..
..| Role |--+..
..+-----------------+.....
..| [+] CanManage() |.....
..+-----------------+.....
..........................
So, I move a function or properties canManage()
to the Role
class.
As @Thomas Kilian mention, your question is more a behaviour feature, than a structural feature. Behaviors are represented as methods or properties, in a class diagram.
UPDATE:
..........................
..+-----------------+.....
..| User |--+..
..+-----------------+..|..«Can Manage Other Users»
..| [+] CanManage() |--+..
..+-----------------+.....
...........^..............
........../ \.............
..........\ /.............
...........v..............
...........|..............
...........|..............
...........|..............
..+-----------------+.....
..| Role |.....
..+-----------------+.....
..........................
Another version may include a self referenced association.
回答3:
- Give the Role class some manage methods which are used for the intended purpose. But behavioral context is better shown in activity or sequence diagrams where you can elaborate what the "manage" does.
- Add an association from User to SwipeCard and name it "use". Further add an association from SwipeCard to Room and name it "opens".
Re 1:
these are the methods to manipulate roles and
shows how the manager uses them. The constraint tells that only the manager may use this method.
来源:https://stackoverflow.com/questions/35755928/how-to-associate-these-classes-in-uml-class-analysis-diagram