英文:
How to model a self-blocking relationship between users in UML?
问题
我正在开发一个用户管理系统,我需要对用户之间的自我屏蔽关系进行建模。用户应该有能力屏蔽自己。我正在使用UML来表示我的系统的类和关系。我目前有一个代表系统中用户的User类。现在,我需要引入用户能够屏蔽自己的概念。我该如何在UML中表示这种关系?
我考虑用户应该与自己建立关系,这是否会产生一个新的类叫做BlockedUser?
英文:
I am working on a user management system, and I need to model a self-blocking relationship between users. A user should have the ability to block themselves. I'm using UML to represent my system's classes and relationships. I currently have a User class that represents a user in the system. Now, I need to introduce the concept of a user being able to block themselves. How can I represent this relationship in UML?
i'm thinking that a user should have a relation ship with him self user and that should produce a new class called BlockedUser ??
答案1
得分: 1
你已经接近成功了:在User
之间添加一个自关联,命名为blocking
(你可以将一端标记为blocked
,另一端标记为blocked by
),并在两端都使用多重性*
。
即使您可能希望在使用关系数据库管理系统(RDBMS)实现这个设计时添加一个额外的表,但您不需要添加一个额外的类。
如果您想要为每个封锁添加更多信息,例如开始日期、封锁原因,甚至结束日期,您可以将自关联变成一个关联类(从关联边的中间点到具有与关联名称相同的名称的类的虚线)。
英文:
You're almost there: add a self-association between User
, name it blocking
(you may label one end blocked
and the other blocked by
) and use multiplicity *
at both ends.
You do not need an additional class, even if you might want an additional table if you'd implement this design with an RDBMS.
If you want to add more information to each blockage, for example the start date, the reason for blockage and, why not, an end date, you may make the self association an association class (dotted line from the middle of the association edge to a class that has the same name as the association).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论