I have two questions concerning the same UML class diagram. The first one is about how to model template class with UML native types. The second one is about how to handle template classes in OCL constraints.
Question 1: template class
I would like to use a template class for intervals and represent it using UML standards. Intervals must be usable with integers and floats. The best method I found so far is the following:
The idea here is to have a template class, with parameter T
being a superclass of either Integer
and Float
classes.
The problem I see is that I need to redefine the basic types of UML in order to group them. I would like to know if there is a clean way to define a template class and saying that T
is either of type integer
or float
(being here the primitives of UML).
Question 2: OCL constraints for template classes
The second aspect in my problem is that I want to be able to add OCL constraints to say that my intervals must contain at least 2 elements. The problem is that the rules must not be the same depending on the binding of T
in the previous class diagram.
For floats:
context Interval
inv : self.supBound > self.infBound
For integers:
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.