Inheritance 继承依赖于属性值的UML类图

Inheritance 继承依赖于属性值的UML类图,inheritance,uml,class-diagram,Inheritance,Uml,Class Diagram,示例如下: ----------- -------------------- | X | 1..1 0..1 | <<abstract>> | | |<>------------| Y | |-----------| |--------------------| | +a:bool |

示例如下:

 -----------                -------------------- 
|     X     | 1..1    0..1 |    <<abstract>>    |
|           |<>------------|         Y          |
|-----------|              |--------------------|
| +a:bool   |              | +b:positiveInteger |
'-----------'              '--------------------'
------------
|X | 1..10..1 ||
||-------------------Y|
|-----------|              |--------------------|
|+a:bool | |+b:positiveInteger|
'-----------'              '--------------------'
在现实世界中,根据以下规则,抽象Y可以是具体的a、B或C:

  • a
    true
    时,Y为a类
  • a
    false
    b==1
    时,Y为b类
  • a
    false
    b>1
    时,Y为C类
您将如何在UML类图中建模这些继承规则?

您可以使用langauge进行建模

首先,您应该扩展您的图表,并引入三个具体的子类,
A
B
,以及
Y
C
,然后您需要这样的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)))

我不会的。这些是侧约束,不属于类图本身。对于XML文档来说,似乎也很有效。