UML类属性基数:至少有一个这样的但不是没有的

问题描述:

我有一个类,它存储了一些摄影EXIF所需的数据。有选择的requierement:UML类属性基数:至少有一个这样的但不是没有的

我需要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

我会定义/得出相应的UML架构,但我不知道如何来模拟这种想法“基数选项“。任何想法?

您只需将包括这样的约束:

enter image description here

注:

  • 你宁愿使用!= Null等,以使它成为一个布尔表达式。我只是复制你的类似SQL的语法。
  • 我没有包含所有属性。
  • 该约束也可以用OCL编写,这使得它更加正式(对于坚持这一点的人)。但是,我的OCL还不够流畅,我可以把它写得很好。

至于建议的@Thomas基利安, OCL是正式确定这些约束上的UML一个干净的方式,这将是:

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