2017-09-13 61 views
1

我有一個類,它存儲了一些攝影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架構,但我不知道如何來模擬這種想法「基數選項「。任何想法?

回答

1

您只需將包括這樣的約束:

enter image description here

注:

  • 你寧願使用!= Null等,以使它成爲一個布爾表達式。我只是複製你的類似SQL的語法。
  • 我沒有包含所有屬性。
  • 該約束也可以用OCL編寫,這使得它更加正式(對於堅持這一點的人)。但是,我的OCL還不夠流暢,我可以把它寫得很好。
1

至於建議的@Thomas基利安, OCL是正式確定這些約束上的UML一個乾淨的方式,這將是:

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