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
Because the separation between integer and real intervals is done at the class level, the OCL differentiation is straightforward. Thus the constraints are as follows:
context IntegerInterval
inv: ...
context RealInterval
inv: ...
Anyway, I'm still open to other suggestions :)