Methods
No edit summary
No edit summary
Line 1: Line 1:
You may define methods in classes to and implement these with OCL:
You may define methods in classes and implement these with OCL:


[[File:My method.png|frameless|419x419px]]
[[File:My method.png|frameless|419x419px]]
Line 7: Line 7:
[[File:Method ocl.png|frameless|411x411px]]
[[File:Method ocl.png|frameless|411x411px]]


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:
Notice that since this was a method, MDriven will treat your OCL as EAL – something that has side effects. In this case, our method does not have any side effects and we 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:


[[File:Method ocl2.png|frameless|415x415px]]
[[File:Method ocl2.png|frameless|415x415px]]
Line 13: Line 13:
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 ====
==== Parameters and Return Types ====
You give parameters and return types in this format:
You give parameters and return types in this format:
  SomeMethod(myparam:String):String
  SomeMethod(myparam:String):String
Line 23: Line 23:
  SomeMethodThatReturnsList(myparam:String,SomeOtherParam:Integer,aListOfValue:Collection(String)):Collection(String)
  SomeMethodThatReturnsList(myparam:String,SomeOtherParam:Integer,aListOfValue:Collection(String)):Collection(String)
  SomeMethodThatReturnsList(myparam:String,SomeOtherParam:Integer,aListOfValue:Collection(SomeClass)):Collection(SomeClass)
  SomeMethodThatReturnsList(myparam:String,SomeOtherParam:Integer,aListOfValue:Collection(SomeClass)):Collection(SomeClass)
[[Category:OCL]]
[[Category:OCL]]

Revision as of 08:07, 28 February 2023

You may define methods in classes and implement these with OCL:

My method.png

You will in the OCL implementation in the Body-property:

Method ocl.png

Notice that since this was a method, MDriven will treat your OCL as EAL – something that has side effects. In this case, our method does not have any side effects and we 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:

Method ocl2.png

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)
This page was edited 1 days ago on 06/17/2024. What links here