2012-10-20 31 views
0

該示例以下:具有取決於屬性繼承UML類圖值

-----------    -------------------- 
|  X  | 1..1 0..1 | <<abstract>> | 
|   |<>------------|   Y   | 
|-----------|    |--------------------| 
| +a:bool |    | +b:positiveInteger | 
'-----------'    '--------------------' 

在現實世界中,抽象的Y可以是一個具體的A,B或C,根據以下規則:

  • atrue,Y是A類;
  • afalseb == 1,Y是B類;
  • afalseb > 1,Y是C類。

如何在UML類圖中對這些繼承規則進行建模?

+0

我不會。這些是側面約束,不屬於類圖本身。 –

回答

1

您可以使用OCL語言來做到這一點。

首先,你應該延長您的圖表,介紹三個具體子類,AB,和YC,那麼你就需要一個OCL約束是這樣的:

context X: 
inv: (self.a implies self.y isOclTypeOf(A)) and 
    (((not self.a) and (not self.y.isOclUndefined())) implies (self.y.b = 1 implies self.y.isOclTypeOf(B))) and 
    (((not self.a) and (not self.y.isOclUndefined())) implies (self.y.b > 1 implies self.y.isOclTypeOf(C))) 
+0

[Schematron](http://en.wikipedia.org/wiki/Schematron)似乎也適用於XML文檔。 –