Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » How to write OCL for accessing operation parameters
How to write OCL for accessing operation parameters [message #648612] Thu, 13 January 2011 11:35 Go to next message
Andreas Maier is currently offline Andreas Maier
Messages: 32
Registered: July 2009
Member
Here is another question that did not become clear to me when consulting
the OMG OCL 2.0 spec:

7.3.4 "Pre- and Postconditions" states:

"The contextual instance self then is an instance of the type that owns
the operation or method as a feature."

It then goes on to give the example:

context Typename::operationName(param1 : Type1, ... ): ReturnType
pre : param1 > ...
post: result = ...

The spec text (as I understand it) states that the context is an
instance of a class.

The context statement of the example suggests (to me) that the context
is the operation itself.

The OCL body of the example accesses the parameters without any usage of
"self".

That is all a bit inconsistent to me, but maybe I just don't understand
it right.

I'd like to understand what "self" in a precondition resolves to. My
assumption is it resolves to the instance the method is invoked on.

I'd like to understand how to access the value of a parameter of a
method invocation on an instance. Does that not need to start with "self" ?

Andy
Re: How to write OCL for accessing operation parameters [message #648930 is a reply to message #648612] Sat, 15 January 2011 13:55 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi Andreas

If you're familiar with Java or C++ you should not find it odd at all.
Just exchange self/this. The semantics of name visibility/usage are very
similar (until you get to implicit source for iterators).

self/this is an instance of the class, and parameters are local variables.

Regards

Ed Willink



On 13/01/2011 16:35, Andreas Maier wrote:
> Here is another question that did not become clear to me when
> consulting the OMG OCL 2.0 spec:
>
> 7.3.4 "Pre- and Postconditions" states:
>
> "The contextual instance self then is an instance of the type that
> owns the operation or method as a feature."
>
> It then goes on to give the example:
>
> context Typename::operationName(param1 : Type1, ... ): ReturnType
> pre : param1 > ...
> post: result = ...
>
> The spec text (as I understand it) states that the context is an
> instance of a class.
>
> The context statement of the example suggests (to me) that the context
> is the operation itself.
>
> The OCL body of the example accesses the parameters without any usage
> of "self".
>
> That is all a bit inconsistent to me, but maybe I just don't
> understand it right.
>
> I'd like to understand what "self" in a precondition resolves to. My
> assumption is it resolves to the instance the method is invoked on.
>
> I'd like to understand how to access the value of a parameter of a
> method invocation on an instance. Does that not need to start with
> "self" ?
>
> Andy
Previous Topic:How to write OCL that tests an attribute value for null
Next Topic:[Announce] MDT/OCL 3.1.0 M4 is now available
Goto Forum:
  


Current Time: Thu Jul 24 09:09:07 EDT 2014

Powered by FUDForum. Page generated in 0.10125 seconds