2

我有两个关于同一个 UML 类图的问题。第一个是关于如何使用 UML 原生类型对模板类建模。第二个是关于如何处理 OCL 约束中的模板类。

问题一:模板类

我想为间隔使用模板类并使用 UML 标准表示它。间隔必须可用于整数和浮点数。到目前为止,我发现的最佳方法如下:

迄今为止找到的最佳解决方案

这里的想法是有一个模板类,参数T是类的超IntegerFloat

我看到的问题是我需要重新定义 UML 的基本类型以便对它们进行分组。我想知道是否有一种干净的方法来定义模板类并说它T是类型integerfloat(这里是 UML 的原语)。

问题 2:模板类的 OCL 约束

我的问题的第二个方面是我希望能够添加 OCL 约束来说明我的间隔必须包含至少 2 个元素。问题是规则必须根据T前面类图中的绑定不同而不同。

对于花车:

context  Interval
inv :    self.supBound > self.infBound

对于整数:

context Interval
inv :   (self.infBoundIncluded and self.supBoundIncluded) implies supBound - infBound >= 1

context Interval
inv :   (not(self.infBoundIncluded) and self.supBoundIncluded) implies supBound - infBound >= 2

context Interval
inv :   (self.infBoundIncluded and not(self.supBoundIncluded)) implies supBound - infBound >= 2

context Interval
inv :   (not(self.infBoundIncluded) and not(self.supBoundIncluded)) implies supBound - infBound >= 3

So I need to find a way in OCL to say that some rules only apply when T is bound to Integer, and others when it is bound to Float. I am not an expert in OCL, and I couldn't find any helpful information, so I'm asking for some help.

Thanks in advance,

Bastien.

4

1 回答 1

1

After more research, I came out with the following solutions:

Question 1

The solution is to use a template class with a generic type (this class won't be instantiable according to UML standards), and to bind it with realization classes. The corresponding UML class diagram is as follows:

在此处输入图像描述

Here, we have two usable classes IntegerInterval and RealInterval derived from a general template class Interval, which keeps things simple, in addition to using UML basic types integer and real.

Question 2

因为整数和实数区间的分离是在类级别上完成的,所以 OCL 微分很简单。因此,约束如下:

context IntegerInterval
inv:    ...

context RealInterval
inv:    ...

无论如何,我仍然愿意接受其他建议:)

于 2013-11-24T15:20:53.067 回答