Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optional parameter with UML class diagram

Tags:

uml

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?

like image 740
Alexander Kucheryuk Avatar asked Oct 31 '15 01:10

Alexander Kucheryuk


People also ask

Do you include parameters in class diagram?

The arg list is a list of parameter types (e.g., int, double, String); parameter names are not included in the UML class diagram.

What is parameter in UML?

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.

How do you represent an interface in UML class diagram?

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.


1 Answers

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

like image 179
Geert Bellekens Avatar answered Oct 11 '22 04:10

Geert Bellekens