in,out,inout,return parameter direction in UML
Asked Answered
C

5

14

As i read the following concepts through UML specification promoted by OMG 2.5 (Beta) as:

in: Indicates that Parameter values are passed in by the caller.

inout:Indicates that Parameter values are passed in by the caller and then back out to the caller.

out:Indicates that Parameter values are passed out to the caller.

return:Indicates that Parameter values are passed as return values back to the caller.

Does this mean that the "in" is as call by value and "inout" as call by reference?

could you please clarify each one of those concepts a bit?

Chaisson answered 10/2, 2013 at 15:44 Comment(0)
S
4

• in - An input Parameter (may not be modified).

• out - An output Parameter (may be modified to communicate information to the caller).

• inout - An input Parameter that may be modified.

• return -A return value of a call.

Suit answered 29/11, 2013 at 8:29 Comment(1)
Unfortunately, this is an absolutely wrong answer, please review it.Adelladella
R
3

Call by reference is one possible implementation of inout and out, yes.

Remember that UML is describing a behavior in a language-neutral way. It is up to the implementation of a given interface in an actual language to determine what this means.

In a language like Ada, with language-level in , out, and in out parameters, this can be expressed directly in the language, and the compiler can decide where reference or copy is a better implementation. In a language like Python, where all parameters are passed by reference (sort of), this notation of intent at the UML level does not result in any distinction at the implementation level. And in a language like C, with explicit pointer types and all parameters passed by value, these intents expressed in UML turn into explicit address references and pointer dereferences.

In other words, the short answer is "yes, that's roughly what it means, but it may not be what it does".

Rizal answered 10/2, 2013 at 16:1 Comment(1)
thank you @Rizal for clarifications.i like to know when modeling in UML, if i put "in" direction for a parameter ?what this mean(semantically)? in the case of "out"what this mean? and also "inout" and "return"what this mean?Chaisson
O
0

The key thing to remember about UML is that it is designed to be universal, it is intended to be independent of implementation platform. Specifically it is a PIM, a platform-independent model. So it is a misnomer to use platform specific implementation semantics such as 'by value' and 'by reference'.

Now in practice defining those domain specific semantics is one job of the Project Architect and in many cases those semantics you mention are valid, but that is not always the case.

Model Driven Architecture (MDA) plus Platform Profile = Platform Specific Design.

Outpour answered 11/2, 2013 at 13:41 Comment(2)
thank you @Martin Spamer. if those guys are domain specific why written through UML spec? i like to understand the semantic of each one of them and also if we ignore those implementation details ,how can be able to generate code from this model?Chaisson
Well ideally your Model should remain universal and your Architect should define a platform profile. This defines show the universal semantics are transformed to platform specific semantics during code generation or round-trip engineering. I've added some links above that should help.Outpour
B
0

When looking in the official UML specification, we find a slight change:

in: Indicates that Parameter values are passed in by the caller.

inout:Indicates that Parameter values are passed in by the caller and (possibly different) values passed out to the caller.

out:Indicates that Parameter values are passed out to the caller.

return:Indicates that Parameter values are passed as return values back to the caller.

And it contains a note: no more than one parameter may be marked as a return parameter.

I could not find any further definitions/clarifications on this ParameterDirectionKind enumeration.

I.e. UML does not want to specify this further. And most certainly it does not specify any one of them as pass by reference or pass by value.

Backsheesh answered 25/3, 2018 at 11:34 Comment(1)
UML also specifies the ParameterEffectKind of a parameter. It can be 'create', 'read', 'update' or 'delete'. This means that the parameters must be passed by reference, otherwise the ParameterEffectKind would be meaningless.Corfu
A
0

Neither "in" means that a parameter is passed by value nor "inout" means that a parameter is passed by reference.

According to clause 13.2.3.2 Behavior Parameters of UML Specification:

When a Behavior is invoked, argument values may be provided corresponding to Parameters with direction “in” or “inout”, as constrained by the multiplicity of those Parameters. ... Argument values are available to affect the course of the invoked Behavior execution

Clause 9.4.3.5 Parameters says:

The effect property may be used to specify what happens to objects passed in or out of a Parameter.

For example "delete" effect means that:

Objects that are values of the parameter do not exist after executions of the behavior are finished.

And then it is explicitly stated that:

Only in and inout Parameters may have a "delete" effect

Pass by value or pass by reference are the implementation methods and both can be used to implement in, inout and out parameters. In C you may pass pointer to function by value and delete the object the pointer points to, if UML model asks you to do so.

Adelladella answered 29/5, 2020 at 15:47 Comment(3)
My definition of "pass by value" would be: the method receives a copy of the original object passed by the caller. In other words, the method cannot modify the original object. In UML, this is true for datatypes, but not for other objects, otherwise the effect properties 'update' and 'delete' would be meaningless. My conclusion is, that the non-datatype parameters with direction in or inout are passed by reference, i.e. the method refers to the same object as the caller.Corfu
@Corfu const reference parameter of a method in C++ is an example of "in" parameter passed by reference which the method cannot modify.Adelladella
In UML, this "in" parameter would have ParameterEffectKind = read. In UML, datatypes are passed by value and the rest is passed by reference.Corfu

© 2022 - 2024 — McMap. All rights reserved.