No edit summary |
Hans Karlsen (talk | contribs) No edit summary |
||
Line 12: | Line 12: | ||
We can then use our IsQuery method in any expression in OCL. Thing.allinstances- >select(x|x.MyMethod(x.SomeInt)) | We can then use our IsQuery method in any expression in OCL. Thing.allinstances- >select(x|x.MyMethod(x.SomeInt)) | ||
==== Parameters and return types ==== | |||
You give parameters and return types in this format: | |||
SomeMethod(myparam:String):String | |||
SomeMethod(myparam:String,SomeOtherParam:Integer):String | |||
SomeMethod(myparam:String,SomeOtherParam:Integer,aListOfValue:Collection(String)):String | |||
SomeMethodThatReturnsList(myparam:String,SomeOtherParam:Integer,aListOfValue:Collection(String)):Collection(String) | |||
SomeMethodThatReturnsList(myparam:String,SomeOtherParam:Integer,aListOfValue:Collection(SomeClass)):Collection(SomeClass) |
Revision as of 17:09, 25 January 2021
You may define methods in classes to and implement these with OCL:
You will in the OCL implementation in the Body-property:
Notice that since this was a method MDriven will treat you OCL as EAL – something that is allowed to have side effects. In this case our method do not have any side effects and I may want to be able to use this method in OCL. But trying to use it in OCL will not succeed. Methods with side effects are not recognized by OCL . There is a flag on the Method definition called IsQuery and if this is set we “promise” that it does not have intentional side effects. Now it is seen by OCL:
We can then use our IsQuery method in any expression in OCL. Thing.allinstances- >select(x|x.MyMethod(x.SomeInt))
Parameters and return types
You give parameters and return types in this format:
SomeMethod(myparam:String):String SomeMethod(myparam:String,SomeOtherParam:Integer):String SomeMethod(myparam:String,SomeOtherParam:Integer,aListOfValue:Collection(String)):String SomeMethodThatReturnsList(myparam:String,SomeOtherParam:Integer,aListOfValue:Collection(String)):Collection(String) SomeMethodThatReturnsList(myparam:String,SomeOtherParam:Integer,aListOfValue:Collection(SomeClass)):Collection(SomeClass)