Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Single OCL constraint for multiple properties
Single OCL constraint for multiple properties [message #517163] Fri, 26 February 2010 07:49 Go to next message
Timothy Marc is currently offline Timothy Marc
Messages: 547
Registered: July 2009
Senior Member
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 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4008
Registered: July 2009
Senior Member
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
Re: Single OCL constraint for multiple properties [message #517305 is a reply to message #517280] Fri, 26 February 2010 11:50 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4008
Registered: July 2009
Senior Member
On 26/02/2010 19:01, Ed Willink wrote:
> I'll raise an OMG issue.

Issue 15092.

Should appear on http://www.omg.org/issues/ocl2-rtf.open.html soon.

Regards

Ed Willink
Previous Topic:Operation, Instantiation and post clause: Invalid Class?
Next Topic:How to count associative classes in a UML model
Goto Forum:
  


Current Time: Mon Jul 28 12:34:16 EDT 2014

Powered by FUDForum. Page generated in 0.01539 seconds