Thursday 9 May 2024

PlantUML: Declare default values to procedure, function parameters

You can assign default values to function or procedure parameters.

!function $sum($a=5, $b=6)
	!global $counter = $counter + 1
	!return $a + $b
!endfunction

$sum() : Since I do not pass any arguments, a =5, b=6 are used here
$sum(20): a= 20, b=6
$sum(20, 30): a=20, b=30

 defaultValues.txt

 

@startuml

!global $counter = 1

!function $sum($a=5, $b=6)
	!global $counter = $counter + 1
	!return $a + $b
!endfunction

sys1 -> sys2 : $counter. sum() is $sum()
sys1 -> sys2 : $counter. sum(20) is $sum(20)
sys1 -> sys2 : $counter. sum(20, 30) is $sum(20, 30)

@enduml


Above snippet generate below diagram.



Previous                                                    Next                                                    Home

No comments:

Post a Comment