Home » Modeling » OCL » Preconditions and inheritance
|
Re: Preconditions and inheritance [message #20030 is a reply to message #19988] |
Fri, 27 April 2007 12:12 |
Eclipse User |
|
|
|
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 #20097 is a reply to message #20068] |
Fri, 27 April 2007 14:05 |
Eclipse User |
|
|
|
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 |
Hao Zhang 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 #40088 is a reply to message #39997] |
Tue, 09 October 2007 14:20 |
Eclipse User |
|
|
|
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.
>>
|
|
|
Goto Forum:
Current Time: Thu Sep 19 10:47:24 GMT 2024
Powered by FUDForum. Page generated in 0.03970 seconds
|