UML类属性基数:至少有一个这样的但不是没有的
问题描述:
我有一个类,它存储了一些摄影EXIF所需的数据。有选择的requierement:UML类属性基数:至少有一个这样的但不是没有的
我需要FocalLengthIn35mmFilm
或(FocalLength
和FocalPlaneXResolution
和FocalPlaneYResolution
)。
这将对应于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架构,但我不知道如何来模拟这种想法“基数选项“。任何想法?
答
至于建议的@Thomas基利安, OCL是正式确定这些约束上的UML一个干净的方式,这将是:
context Photo inv :
(
self.FocalLengthIn35mmFilm->notEmpty()
or (
self.FocalLenght->notEmpty() and
self.FocalPlaneXResolution->notEmpty() and
self.FocalPlaneYResolution->notEmpty()
)
)