How to associate these classes in UML Class Analys

2020-04-17 02:28发布

I'm trying to design UML Analysis Class Diagram for a college project. My UML Diagram looks like this: enter image description here

I have encountered two different problems:

  1. User can have multiple roles. A user with Manager role can manage other users and their roles. How to illustrate this association in UML?
  2. User uses SwipeCard to access a room. How to show this association in UML?

3条回答
Ridiculous、
2楼-- · 2020-04-17 02:51

You have a really good start to an analysis model. Some things I would do:

  • Reify the association between User and Role (or make it an association class) called Role Assignment.
  • Add a verb-phrased property name to every end of every association. For example, Manager authorizes Role Assignment and Role Assignment authorized by Manager.

Here's an example first cut, off the top of my head:

enter image description here

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!

查看更多
女痞
3楼-- · 2020-04-17 02:51
  1. 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.
  2. 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:

enter image description here these are the methods to manipulate roles and

enter image description here shows how the manager uses them. The constraint tells that only the manager may use this method.

查看更多
姐就是有狂的资本
4楼-- · 2020-04-17 03:04

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.

查看更多
登录 后发表回答