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?

Andrew
  • 713
  • 3
  • 10
  • 19

5 Answers5

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".

jimwise
  • 454
  • 3
  • 8
  • thank you @jimwise 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? – Andrew Feb 12 '13 at 09:15
3

• 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.

Carlos
  • 1,522
  • 5
  • 14
  • 26
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.

Martin Spamer
  • 5,437
  • 28
  • 44
  • 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? – Andrew Feb 12 '13 at 09:16
  • 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. – Martin Spamer Feb 12 '13 at 10:47
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.

Jens Wagemaker
  • 354
  • 3
  • 13
  • 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. – www.admiraalit.nl Aug 24 '22 at 14:56
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.

zer0hedge
  • 449
  • 3
  • 12
  • 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. – www.admiraalit.nl Aug 24 '22 at 14:50
  • @www.admiraalit.nl const reference parameter of a method in C++ is an example of "in" parameter passed by reference which the method cannot modify. – zer0hedge Aug 26 '22 at 10:52
  • In UML, this "in" parameter would have ParameterEffectKind = read. In UML, datatypes are passed by value and the rest is passed by reference. – www.admiraalit.nl Aug 28 '22 at 19:28