UML class 属性基数:至少其中之一但不是 none

UML class attribute cardinality: at least one of these but not none

我有一个 class,用于存储照片 EXIF 中的一些必需数据。要求中有选项:

我需要FocalLengthIn35mmFilm 或 (FocalLengthFocalPlaneXResolutionFocalPlaneYResolution).

它将对应于 SQL 语句:

create table Photo(
  /* Whatever */
  FocalLengthIn35mmFilm FLOAT null,
  FocalLength FLOAT null,
  FocalPlaneXResolution FLOAT null,
  FocalPlaneYResolution FLOAT null,
  constraint AtLeastOneFocal CHECK (
    FocalLengthIn35mmFilm is not null OR (
        FocalLength is not null AND
        FocalPlaneXResolution is not null AND
        FocalPlaneYResolution is not null
        )
  )
)

xsd 架构类似于 this answer

我会 define/draw 相应的 UML 模式,但我不知道如何对此建模 "option in cardinality"。有什么想法吗?

您只需包含这样的约束:

备注:

  • 你宁愿使用 != Null 或类似的东西使它成为一个 bool 表达式。我只是复制了你的 SQL-like 语法。
  • 我没有包含所有属性。
  • 约束也可以用 OCL 编写,这样更正式(对于那些坚持这样做的人)。然而,我的 OCL 仍然不是很流畅,我可以把它写得井井有条。

正如@Thomas Kilian 所建议的, OCL 是一种将这些约束形式化为 UML 的简洁方法,它将是:

context Photo inv : 
(
self.FocalLengthIn35mmFilm->notEmpty() 
  or (
  self.FocalLenght->notEmpty() and
  self.FocalPlaneXResolution->notEmpty() and
  self.FocalPlaneYResolution->notEmpty()
  )
)