简体   繁体   中英

How to associate these classes in UML Class Analysis Diagram?

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:

  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?

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:

在此处输入图片说明

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! 😉

  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:

在此处输入图片说明 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM