Is there an official syntax for specifying optional parameter of a method in 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 its default value?
The arg list is a list of parameter types (e.g., int, double, String); parameter names are not included in the UML class diagram.
In UML models, parameters are specific arguments that pass information between behavioral features, such as operations. A parameter has a type and it can have a default value. A parameter specifies the type of an argument and the value it takes in the call to an operation.
An interface specifies a contract. In UML 1.4 interface was formally equivalent to an abstract class with no attributes and no methods and only abstract operations. An interface may be shown using a rectangle symbol with the keyword «interface» preceding the name.
UML 2.5 has following definition for a parameterlist
<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)
The type expression is not optional so you can't leave that out, but I guess you can think of a convention where you use something like Unspecified
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With