UML class 图的可选参数
Optional parameter with UML class diagram
在 UML class 类型图中是否有指定方法的可选参数的官方语法?
比如我有一个方法:
public function abc( $arg = 0) { ... return void; }
如何指示 $arg 是可选参数及其默认值?
UML 2.5 对参数列表有以下定义
<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.
所以你可以使用
+ abc($arg : Integer = 0)
类型表达式不是可选的,因此您不能将其遗漏,但我想您可以想到使用 Unspecified
之类的约定
来自 UML 2.5 规范章节。 9.4.3.4 参数 p. 107:
A Parameter is a specification of an argument used to pass information into or out of an invocation of a BehavioralFeature. The Type and Multiplicity of a Parameter restrict what values may be passed, how many, and whether the values are ordered. The Multiplicity defines a lower and upper bound on the values passed to the Parameter at runtime. A lower bound of zero means the Parameter is optional. Actions using the Parameter may execute without having a value for optional Parameters. A lower bound greater than zero means values for the Parameter are required to arrive sometime during the execution of the action.
If a defaultValue is specified for a Parameter, then it is evaluated at invocation time and used as the argument for this Parameter if and only if no argument is supplied at invocation of the BehavioralFeature.
但是,class 图演示中通常不会显示多重性。信息仅存储在元数据中。至少我从未见过任何工具使用 Geert 的回答所指出的符号。
在 UML class 类型图中是否有指定方法的可选参数的官方语法?
比如我有一个方法:
public function abc( $arg = 0) { ... return void; }
如何指示 $arg 是可选参数及其默认值?
UML 2.5 对参数列表有以下定义
<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.
所以你可以使用
+ abc($arg : Integer = 0)
类型表达式不是可选的,因此您不能将其遗漏,但我想您可以想到使用 Unspecified
来自 UML 2.5 规范章节。 9.4.3.4 参数 p. 107:
A Parameter is a specification of an argument used to pass information into or out of an invocation of a BehavioralFeature. The Type and Multiplicity of a Parameter restrict what values may be passed, how many, and whether the values are ordered. The Multiplicity defines a lower and upper bound on the values passed to the Parameter at runtime. A lower bound of zero means the Parameter is optional. Actions using the Parameter may execute without having a value for optional Parameters. A lower bound greater than zero means values for the Parameter are required to arrive sometime during the execution of the action.
If a defaultValue is specified for a Parameter, then it is evaluated at invocation time and used as the argument for this Parameter if and only if no argument is supplied at invocation of the BehavioralFeature.
但是,class 图演示中通常不会显示多重性。信息仅存储在元数据中。至少我从未见过任何工具使用 Geert 的回答所指出的符号。