Single OCL constraint for multiple properties [message #517163] |
Fri, 26 February 2010 07:49  |
Eclipse User |
|
|
|
Hi all,
i've a question concerning OCL for properties contained in different
classifiers. Let's assume, we have two signals:
Signal A {xyz:Integer}
Signal B {xyz:Integer}
Both properties are restricted by the same kind of constraint. In OCL i
would use the following syntax:
context A
inv: self.xyz > 0
context B
inv: self.xyz > 0
Since we have a lot of Signals, sharing similar properties, it is a
quite annoying and repitive task to define these constraints in each
signal separately. I know, generaliaztion might be the answer, but we
didn't want the signals to be compatible with each other.
In UML it is possible to define a constraint somewhere in the model and
refer to elements which will be constrained by this single constraint.
Is this also possible with OCL? If so, how does the syntax look like?
Would the constraint point to the signals and than just state the
invariant like this:
self.xyz > 0
Cheers and Thanks
Timothy
|
|
|
Re: Single OCL constraint for multiple properties [message #517280 is a reply to message #517163] |
Fri, 26 February 2010 14:01  |
Eclipse User |
|
|
|
Hi Timothy
This cannot be done in a typesafe Object Oriented language, you need a
'macro' facility such as C++ templates. Type safety requires that the
validity of xyz can be validated against XYZ.xyz, so A and B must
implement (in Java terms) XYZ. This does not require that they extend
(in Java terms) XYZ. XYZ is just a mix-in to define that A and B comply
with a common interface.
I have vaguely wondered whether OCL should support an extension
capability for inheritance as well as Properties and Operations. You
seem to provide a good justification for:
context XYZ
inv: self.xyz > 0
context A extends XYZ
context B extends XYZ
I'll raise an OMG issue.
Regards
Ed Willink
On 26/02/2010 12:49, Timothy Marc wrote:
> Hi all,
>
> i've a question concerning OCL for properties contained in different
> classifiers. Let's assume, we have two signals:
>
> Signal A {xyz:Integer}
> Signal B {xyz:Integer}
>
> Both properties are restricted by the same kind of constraint. In OCL i
> would use the following syntax:
>
> context A
> inv: self.xyz > 0
>
> context B
> inv: self.xyz > 0
>
> Since we have a lot of Signals, sharing similar properties, it is a
> quite annoying and repitive task to define these constraints in each
> signal separately. I know, generaliaztion might be the answer, but we
> didn't want the signals to be compatible with each other.
>
> In UML it is possible to define a constraint somewhere in the model and
> refer to elements which will be constrained by this single constraint.
> Is this also possible with OCL? If so, how does the syntax look like?
> Would the constraint point to the signals and than just state the
> invariant like this:
>
> self.xyz > 0
>
> Cheers and Thanks
> Timothy
|
|
|
|
Powered by
FUDForum. Page generated in 0.03407 seconds