问题描述
在UML类图中,我将如何建模一个可以在一周之内每天工作而又不知道具体情况的导师呢?在我当前的解决方案中:一名或多位导师在一周的1天或更长时间里工作.
In a UML class diagram, how would I model a tutor can work multiple days of the week without knowing specifically? In my current solution: 1 or more tutors work on 1 or more days of the week.
推荐答案
由于教师工作的天数只是一个属性,似乎没有任何特定的结构可以围绕它构建类,因此应该类型为 DaysOfTheWeek
且多样性为 1..7
的内联属性.另外,由于您不能在同一天两次工作,因此应添加 unique
约束.您的论证(在类 Tutor
内)应如下所示:
Since the list of days when Tutor work is only an attribute and doesn't seem to have any specific structure to build a class around it, it should rather be an inline attribute with type DaysOfTheWeek
and multiplicity 1..7
. Also since you can't work twice at the same day you should add unique
constraint.Your argument (within the class Tutor
) should look like that:
-workingDays : DaysOfTheWeek [1..7] {unique}
图中您的Tutor一方的多重性表明,每个可能的工作日(枚举值)至少有一位Tutor.如果是这样,则可以将其添加为类约束.出于可追溯性原因,您可以将 Tutor
的依赖项(带空心箭头的虚线)添加到 DaysOfTheWeek
中,但这不是必需的.
The multiplicity on Tutor side in your diagram suggests you have at least one Tutor for each possible working day (enumeration value). If this is true you can add this as a class constraint then.For traceability reasons you can add dependency (dashed line with open arrow) from Tutor
to DaysOfTheWeek
, but that's not necessary.
如果您有理由建立一个专用的类,那么您的图表可以看起来像这样
If you have a reason to build a dedicated class, your diagram can look like this
很抱歉,由于某种原因,即使放置了我的工具,它也不会导出构造型.DaysOfTheWeek应该具有枚举,但是在导出中丢失了.
I'm sorry, for some reason my tool doesn't export the stereotype even though I've placed it. DaysOfTheWeek should have the Enumeration but it was lost in the export.
一般性说明:一个类必须有一个名称.不能只是刻板印象.
A general side remark: a class has to have a name. It can't be just a stereotype.
这篇关于UML类图-枚举建模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!