Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Preconditions and inheritance
Preconditions and inheritance [message #19988] Fri, 27 April 2007 09:02 Go to next message
Youmm P. is currently offline Youmm P.Friend
Messages: 140
Registered: July 2009
Senior Member
Hello,

While in Java all objects automatically inherit the methods of their
superclass(es), in C++ you have to add the 'virtual' keyword.

If I have a class B that inherits from a class A which contains a method
'start'

context A::start():void pre
// ...

is no doubt a valid constraint.

But what about "context B::start():void" if start is not redefined in B ?

This would have a meaning in Java but not in C++ if start is not virtual.

Since OCL is language independent how should I handle this ?

I tried to do something like "context B::start():void pre..." without
success.

I'm using an Ecore model and inheritance works well for attributes.

Thanks for your help,
Youmm.
Re: Preconditions and inheritance [message #20030 is a reply to message #19988] Fri, 27 April 2007 12:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Youmm,

In OCL, it is not necessary to redefine an inherited operation or attribute
in a specializing classifier in order to add pre/post conditions or
redefine the body expression.

What you are trying to do should work. In what way is it not? Is it not
parsing?

You will find examples of this in the
org.eclipse.ocl.ecore.tests.OperationConstraintTest class, which parses
preconditions and body conditions in the Apple context for operations
inherited from Fruit.

Cheers,

Christian


Youmm P. wrote:

> Hello,
>
> While in Java all objects automatically inherit the methods of their
> superclass(es), in C++ you have to add the 'virtual' keyword.
>
> If I have a class B that inherits from a class A which contains a method
> 'start'
>
> context A::start():void pre
> // ...
>
> is no doubt a valid constraint.
>
> But what about "context B::start():void" if start is not redefined in B ?
>
> This would have a meaning in Java but not in C++ if start is not virtual.
>
> Since OCL is language independent how should I handle this ?
>
> I tried to do something like "context B::start():void pre..." without
> success.
>
> I'm using an Ecore model and inheritance works well for attributes.
>
> Thanks for your help,
> Youmm.
Re: Preconditions and inheritance [message #20068 is a reply to message #20030] Fri, 27 April 2007 13:57 Go to previous messageGo to next message
Youmm P. is currently offline Youmm P.Friend
Messages: 140
Registered: July 2009
Senior Member
> What you are trying to do should work. In what way is it not? Is it not
> parsing?
>
Ok I think I get it : with OCLHelper you've got to use setEOperation
with the inherited class and with the method of one of the superclasses.

Thanks for the explanations.
Re: Preconditions and inheritance [message #20097 is a reply to message #20068] Fri, 27 April 2007 14:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Youmm,

I see ... you were using the OCLHelper. Yes, in that case, you specify an
EClass that is not the one that owns the EOperation, but rather inherits
it. The same works for the attribute context.

Cheers,

Christian


Youmm P. wrote:

>
>> What you are trying to do should work. In what way is it not? Is it not
>> parsing?
>>
> Ok I think I get it : with OCLHelper you've got to use setEOperation
> with the inherited class and with the method of one of the superclasses.
>
> Thanks for the explanations.
Re: Preconditions and inheritance [message #39997 is a reply to message #20097] Mon, 08 October 2007 09:16 Go to previous messageGo to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 161
Registered: July 2009
Senior Member
Hi,

I'm also facing this problem, but I can't find setEOperation() in OCLHelper,
but only setOperationContext(), and I have no idea what should I pass the
arguments.

For example, I defined operation "isValid()" in class A, class B inherits A,
how do I configure my OCLHelper to let expression "b.isValid()" work?

Regards,
Hao

"Christian W. Damus" <cdamus@ca.ibm.com>
??????:f0svu5$b9i$1@build.eclipse.org...
>
> Hi, Youmm,
>
> I see ... you were using the OCLHelper. Yes, in that case, you specify an
> EClass that is not the one that owns the EOperation, but rather inherits
> it. The same works for the attribute context.
>
> Cheers,
>
> Christian
>
>
> Youmm P. wrote:
>
>>
>>> What you are trying to do should work. In what way is it not? Is it
>>> not
>>> parsing?
>>>
>> Ok I think I get it : with OCLHelper you've got to use setEOperation
>> with the inherited class and with the method of one of the superclasses.
>>
>> Thanks for the explanations.
>
Re: Preconditions and inheritance [message #40028 is a reply to message #39997] Mon, 08 October 2007 09:53 Go to previous messageGo to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 161
Registered: July 2009
Senior Member
One more word, I also defined some operations in class B (e.g. getPrice()),
and I need an expression like "b.isValid() and b.getPrice()>100" to be
evaluated. Thanks.

"Hao Zhang" <bjzhanghao@21cn.com> д
Re: Preconditions and inheritance [message #40058 is a reply to message #40028] Mon, 08 October 2007 10:20 Go to previous messageGo to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 161
Registered: July 2009
Senior Member
It seems I solved this problem now, I invoked
OCLHelper.setOperationContext() on any method I defined in A, then it works
for all the inherited methods. Is this the right?

"Hao Zhang" <bjzhanghao@21cn.com> д
Re: Preconditions and inheritance [message #40088 is a reply to message #39997] Tue, 09 October 2007 14:20 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Hao,

The arguments to the setOperationContext() method are "context" and
"operation." The first is the classifier context in which you want to
define this constraint and the second is the operation, which may be
defined by the context classifier or inherited by it.

So, doing

EClass a = ... ;
EOperation isValid = ... ;
EClass b = ... ;
OCLHelper<EClassifier, EOperation, ?, Constraint> helper = ... ;

helper.setOperationContext(b, isValid);

Constraint constraint = helper.createPrecondition(...);

is equivalent to this concrete syntax of the context declaration:

context B::isValid() : Boolean
pre: -- some OCL condition

assuming, of course, the A::isValid() has EBoolean or EBooleanObject type.

HTH,

Christian


Hao Zhang wrote:

> Hi,
>
> I'm also facing this problem, but I can't find setEOperation() in
> OCLHelper, but only setOperationContext(), and I have no idea what should
> I pass the arguments.
>
> For example, I defined operation "isValid()" in class A, class B inherits
> A, how do I configure my OCLHelper to let expression "b.isValid()" work?
>
> Regards,
> Hao
>
> "Christian W. Damus" <cdamus@ca.ibm.com>
> ??????:f0svu5$b9i$1@build.eclipse.org...
>>
>> Hi, Youmm,
>>
>> I see ... you were using the OCLHelper. Yes, in that case, you specify
>> an EClass that is not the one that owns the EOperation, but rather
>> inherits
>> it. The same works for the attribute context.
>>
>> Cheers,
>>
>> Christian
>>
>>
>> Youmm P. wrote:
>>
>>>
>>>> What you are trying to do should work. In what way is it not? Is it
>>>> not
>>>> parsing?
>>>>
>>> Ok I think I get it : with OCLHelper you've got to use setEOperation
>>> with the inherited class and with the method of one of the superclasses.
>>>
>>> Thanks for the explanations.
>>
Previous Topic:[Announce] MDT OCL 1.2.0 1.2M2 is available
Next Topic:OCL for UML AssociationClass
Goto Forum:
  


Current Time: Thu Sep 19 10:47:24 GMT 2024

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

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

Back to the top