带UML类图的可选参数

时间:2015-10-31 01:13:34

标签: uml

是否有用于在UML类类型图中指定方法的可选参数的官方语法?

例如,我有一个方法:

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

我如何指出$ arg是一个可选参数及其默认值?

2 个答案:

答案 0 :(得分:5)

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>]* ‘}’]
  •   
     

其中:

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

之类的约定

答案 1 :(得分:0)

来自UML 2.5规范。 9.4.3.4参数p。 107:

  

参数是用于将信息传入或传出BehavioralFeature调用的参数的规范。参数的类型和多重性限制可以传递的值,数量以及值是否有序。 Multiplicity定义了在运行时传递给Parameter的值的下限和上限。零下限表示参数是可选的。使用参数的操作可以在没有可选参数值的情况下执行。大于零的下限意味着参数的值需要在执行操作期间的某个时间到达。

     

如果为Parameter指定了defaultValue,则在调用时对其进行求值,并将其用作此Parameter的参数,当且仅当在调用BehavioralFeature时未提供任何参数时。

但是,多样性通常不会在类图表示中显示。信息仅存储在元数据中。至少我从未见过使用Geert答案指出的符号的任何工具。

相关问题