mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-23 01:09:42 +02:00
Merge pull request #1178 from jgreywolf/1119-SpecifyMethodReturnTypeInClassDiagram
1119 specify method return type in class diagram
This commit is contained in:
@@ -105,7 +105,7 @@ Naming convention: a class name should be composed of alphanumeric (unicode allo
|
||||
|
||||
UML provides mechanisms to represent class members, such as attributes and methods, and additional information about them.
|
||||
|
||||
Mermaid distinguishes between attributes and functions/methods based on if the **parenthesis** `()` are present or not. The ones with `()` are treated as functions/methods, and others as attributes.
|
||||
Mermaid distinguishes between attributes and functions/methods based on if the **parenthesis** `()` are present or not. The ones with `()` are treated as functions/methods, and others as attributes. To indicate a return type for a method, enclose the type within **square brackets** `[]`
|
||||
|
||||
|
||||
There are two ways to define the members of a class, and regardless of whichever syntax is used to define the members, the output will still be same. The two different ways are :
|
||||
@@ -115,8 +115,8 @@ There are two ways to define the members of a class, and regardless of whichever
|
||||
class BankAccount
|
||||
BankAccount : +String owner
|
||||
BankAccount : +BigDecimal balance
|
||||
BankAccount : +deposit(amount)
|
||||
BankAccount : +withdrawl(amount)
|
||||
BankAccount : +deposit(amount) bool
|
||||
BankAccount : +withdrawal(amount)
|
||||
```
|
||||
|
||||
``` mermaid
|
||||
@@ -124,7 +124,7 @@ There are two ways to define the members of a class, and regardless of whichever
|
||||
class BankAccount
|
||||
BankAccount : +String owner
|
||||
BankAccount : +BigDecimal balance
|
||||
BankAccount : +deposit(amount)
|
||||
BankAccount : +deposit(amount) : bool
|
||||
BankAccount : +withdrawl(amount)
|
||||
```
|
||||
|
||||
@@ -133,7 +133,7 @@ There are two ways to define the members of a class, and regardless of whichever
|
||||
class BankAccount{
|
||||
+String owner
|
||||
+BigDecimal balance
|
||||
+deposit(amount)
|
||||
+deposit(amount) bool
|
||||
+withdrawl(amount)
|
||||
}
|
||||
```
|
||||
@@ -142,12 +142,15 @@ class BankAccount{
|
||||
class BankAccount{
|
||||
+String owner
|
||||
+BigDecimal balance
|
||||
+deposit(amount)
|
||||
+deposit(amount) : bool
|
||||
+withdrawl(amount)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### Return Type
|
||||
Optionally you can end the method/function definition with the data type that will be returned
|
||||
|
||||
#### Visibility
|
||||
To specify the visibility of a class member (i.e. any attribute or method), these notations may be placed before the member's name, but it is optional:
|
||||
|
||||
|
Reference in New Issue
Block a user