Optional parameter with UML class diagram

Is there an official syntax for specifying an optional method parameter in a UML class type diagram?

For example, I have a method:

public function abc( $arg = 0) { ... return void; }

How would I indicate that $ arg is an optional parameter and default value?

+4
source share
2 answers

UML 2.5 has the following definition for a parameter list

  • <parameter-list> is a list of Parameters of the Operation in the following format: <parameter-list> ::= <parameter> [‘,’<parameter>]* <parameter> ::= [<direction>] <parameter-name> ‘:’ <type-expression> [‘[‘<multiplicity>’]’] [‘=’ <default>] [‘{‘ <parm-property> [‘,’ <parm-property>]* ‘}’]

Where:

  • <direction> ::= ‘in’ | ‘out’ | ‘inout’ (defaults to ‘in’ if omitted).
  • <parameter-name> is the name of the Parameter.
  • <type-expression> is an expression that specifies the type of the Parameter.
  • <multiplicity> is the multiplicity of the Parameter. (See MultiplicityElement – sub clause 7.5).
  • <default> is an expression that defines the value specification for the default value of the Parameter.
  • <parm-property> indicates additional property values that apply to the Parameter.

So you can use

+ abc($arg : Integer = 0)

A type expression is not optional, so you cannot leave it, but I think you can think of a convention in which you use something like Unspecified

+5
source

From the UML specification 2.5 ch. 9.4.3.4 Parameters p. 107:

A - , BehavioralFeature. , , . , . , . . , , - .

defaultValue, , BehavioralFeature .

, , . . , , , .

0

Source: https://habr.com/ru/post/1613921/


All Articles