Skip to main content


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 16:35 Go to next message
Andreas Maier is currently offline Andreas MaierFriend
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 18:55 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
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: Fri Apr 26 01:26:13 GMT 2024

Powered by FUDForum. Page generated in 0.03904 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top