关于 class 图中的约束

about constraints in class diagram

取下面的class图:

我想对以下约束进行建模: 一个会员不得在同一天参加多个论文答辩。

我会用限定词来表达给定日期,将有零个或一个论文答辩。这看起来像是关联成员端的一个额外矩形,包含字符串 "defence date : DateTime" 和另一端的 [0..1] 的多重性。请参阅 Qualified Association | Applying UML and Patterns: UML Class Diagrams | InformIT 示例。

如果将 {bag} 附加到多重性,它会告诉 reader 该集合是唯一的。

来自上层建筑 2.1.1:

Various other notations can be placed near the end of the line as follows:

  • A multiplicity
  • A property string enclosed in curly braces. The following property strings can be applied to an association end:
    • {subsets <property-name>} to show that the end is a subset of the property called <property-name>.
    • {redefines <end-name>} to show that the end redefines the one named <end-name>.
    • {union} to show that the end is derived by being the union of its subsets.
    • {ordered} to show that the end represents an ordered set.
    • {bag} to show that the end represents a collection that permits the same element to appear more than once. • {sequence} or {seq} to show that the end represents a sequence (an ordered bag).
    • If the end is navigable, any property strings that apply to an attribute.

要添加更多的约束条件,例如日期是唯一的,您应该将该约束条件附加到连接器而不是对象。