Microflow object parsing by reference of by value?

7
When calling a submicroflow (let's call it 'b') from a microflow (let's call it 'a') with some object as parameter, is the object passed by reference of passed by value (copy)? In other words: If I change in my submicroflow 'b' the object passed from microflow 'a' without returning the changed object as return value of 'b' is the object still changed in microflow 'a'? Or not? It's often the case that you want to pass an object to a submicroflow and the submicroflow changes the object, and you want the object back width the changes. What is the best practice in this case? Returning the object from the submicroflow or have both solutions (returning the object and not returning the object) the same effect?
asked
2 answers
8

Primitive variables (like integers, strings, etc...) are passed by value and variables of type object appear to be passed by reference. But technically everything is passed by value. Since you can only change the attributes/associations of an object and not the object itself in microflows; objects behave like they are passed by reference.

answered
6

Everything in microflow, just as in Java is passed by value as "The actual parameter (or argument expression) is fully evaluated and the resulting value is copied into a location being used to hold the formal parameter's value during method/function execution" (see Java is Pass-by-Value).

This means it will work in the same way as Java does. Primitive values will not change in calling microflows when changed in submicroflows, but changes in members of objects defined in a Mendix metamodel (as those objects are represented by a non-primitive type in Java) will be reflected in the calling microflow.

Summarizing, it's not necessary to return objects from submicroflows for the situation you described.

answered