mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-16 13:59:54 +02:00
Update classDiagram.md
This commit is contained in:
@@ -19,13 +19,13 @@ Mermaid can render class diagrams.
|
|||||||
title: Animal example
|
title: Animal example
|
||||||
---
|
---
|
||||||
classDiagram
|
classDiagram
|
||||||
note "From Duck till Zebra"
|
note "From Duck to Zebra"
|
||||||
Animal <|-- Duck
|
Animal <|-- Duck
|
||||||
note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging"
|
note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging"
|
||||||
Animal <|-- Fish
|
Animal <|-- Fish
|
||||||
Animal <|-- Zebra
|
Animal <|-- Zebra
|
||||||
Animal : +int age
|
Animal : +int age
|
||||||
Animal : +String gender
|
Animal : gender +string
|
||||||
Animal: +isMammal()
|
Animal: +isMammal()
|
||||||
Animal: +mate()
|
Animal: +mate()
|
||||||
class Duck{
|
class Duck{
|
||||||
@@ -48,13 +48,13 @@ classDiagram
|
|||||||
title: Animal example
|
title: Animal example
|
||||||
---
|
---
|
||||||
classDiagram
|
classDiagram
|
||||||
note "From Duck till Zebra"
|
note "From Duck to Zebra"
|
||||||
Animal <|-- Duck
|
Animal <|-- Duck
|
||||||
note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging"
|
note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging"
|
||||||
Animal <|-- Fish
|
Animal <|-- Fish
|
||||||
Animal <|-- Zebra
|
Animal <|-- Zebra
|
||||||
Animal : +int age
|
Animal : +int age
|
||||||
Animal : +String gender
|
Animal : gender +string
|
||||||
Animal: +isMammal()
|
Animal: +isMammal()
|
||||||
Animal: +mate()
|
Animal: +mate()
|
||||||
class Duck{
|
class Duck{
|
||||||
@@ -170,6 +170,8 @@ UML provides mechanisms to represent class members such as attributes and method
|
|||||||
|
|
||||||
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 all 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 all others as attributes.
|
||||||
|
|
||||||
|
**Note:** class members can be entered either as __name__ __type__ or __type__ __name__. They can also be entered with, or without the use of a __:__. The examples below uses both methods to demonstrate.
|
||||||
|
|
||||||
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 :
|
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 :
|
||||||
|
|
||||||
- Associate a member of a class using **:** (colon) followed by member name, useful to define one member at a time. For example:
|
- Associate a member of a class using **:** (colon) followed by member name, useful to define one member at a time. For example:
|
||||||
@@ -178,7 +180,7 @@ There are two ways to define the members of a class, and regardless of whichever
|
|||||||
classDiagram
|
classDiagram
|
||||||
class BankAccount
|
class BankAccount
|
||||||
BankAccount : +String owner
|
BankAccount : +String owner
|
||||||
BankAccount : +BigDecimal balance
|
BankAccount : +balance BigDecimal
|
||||||
BankAccount : +deposit(amount)
|
BankAccount : +deposit(amount)
|
||||||
BankAccount : +withdrawal(amount)
|
BankAccount : +withdrawal(amount)
|
||||||
```
|
```
|
||||||
@@ -187,7 +189,7 @@ BankAccount : +withdrawal(amount)
|
|||||||
classDiagram
|
classDiagram
|
||||||
class BankAccount
|
class BankAccount
|
||||||
BankAccount : +String owner
|
BankAccount : +String owner
|
||||||
BankAccount : +BigDecimal balance
|
BankAccount : +balance BigDecimal
|
||||||
BankAccount : +deposit(amount)
|
BankAccount : +deposit(amount)
|
||||||
BankAccount : +withdrawal(amount)
|
BankAccount : +withdrawal(amount)
|
||||||
```
|
```
|
||||||
@@ -198,7 +200,7 @@ BankAccount : +withdrawal(amount)
|
|||||||
classDiagram
|
classDiagram
|
||||||
class BankAccount{
|
class BankAccount{
|
||||||
+String owner
|
+String owner
|
||||||
+BigDecimal balance
|
+balance BigDecimal
|
||||||
+deposit(amount)
|
+deposit(amount)
|
||||||
+withdrawal(amount)
|
+withdrawal(amount)
|
||||||
}
|
}
|
||||||
@@ -208,7 +210,7 @@ class BankAccount{
|
|||||||
classDiagram
|
classDiagram
|
||||||
class BankAccount{
|
class BankAccount{
|
||||||
+String owner
|
+String owner
|
||||||
+BigDecimal balance
|
+balance BigDecimal
|
||||||
+deposit(amount)
|
+deposit(amount)
|
||||||
+withdrawal(amount)
|
+withdrawal(amount)
|
||||||
}
|
}
|
||||||
@@ -222,7 +224,7 @@ Optionally you can end a method/function definition with the data type that will
|
|||||||
classDiagram
|
classDiagram
|
||||||
class BankAccount{
|
class BankAccount{
|
||||||
+String owner
|
+String owner
|
||||||
+BigDecimal balance
|
+balance BigDecimal
|
||||||
+deposit(amount) bool
|
+deposit(amount) bool
|
||||||
+withdrawal(amount) int
|
+withdrawal(amount) int
|
||||||
}
|
}
|
||||||
@@ -232,7 +234,7 @@ class BankAccount{
|
|||||||
classDiagram
|
classDiagram
|
||||||
class BankAccount{
|
class BankAccount{
|
||||||
+String owner
|
+String owner
|
||||||
+BigDecimal balance
|
+balance BigDecimal
|
||||||
+deposit(amount) bool
|
+deposit(amount) bool
|
||||||
+withdrawal(amount) int
|
+withdrawal(amount) int
|
||||||
}
|
}
|
||||||
@@ -247,7 +249,7 @@ Generics can be represented as part of a class definition and also in the parame
|
|||||||
```mermaid-example
|
```mermaid-example
|
||||||
classDiagram
|
classDiagram
|
||||||
class Square~Shape~{
|
class Square~Shape~{
|
||||||
int id
|
-id int
|
||||||
List~int~ position
|
List~int~ position
|
||||||
setPoints(List~int~ points)
|
setPoints(List~int~ points)
|
||||||
getPoints() List~int~
|
getPoints() List~int~
|
||||||
@@ -262,7 +264,7 @@ Square : +getDistanceMatrix() List~List~int~~
|
|||||||
```mermaid
|
```mermaid
|
||||||
classDiagram
|
classDiagram
|
||||||
class Square~Shape~{
|
class Square~Shape~{
|
||||||
int id
|
-id int
|
||||||
List~int~ position
|
List~int~ position
|
||||||
setPoints(List~int~ points)
|
setPoints(List~int~ points)
|
||||||
getPoints() List~int~
|
getPoints() List~int~
|
||||||
@@ -433,7 +435,7 @@ namespace BaseShapes {
|
|||||||
class Triangle
|
class Triangle
|
||||||
class Rectangle {
|
class Rectangle {
|
||||||
double width
|
double width
|
||||||
double height
|
height double
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -444,7 +446,7 @@ namespace BaseShapes {
|
|||||||
class Triangle
|
class Triangle
|
||||||
class Rectangle {
|
class Rectangle {
|
||||||
double width
|
double width
|
||||||
double height
|
height double
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -586,11 +588,11 @@ classDiagram
|
|||||||
}
|
}
|
||||||
class IdCard{
|
class IdCard{
|
||||||
-id : int
|
-id : int
|
||||||
-name : string
|
-string name
|
||||||
}
|
}
|
||||||
class Bike{
|
class Bike{
|
||||||
-id : int
|
-id : int
|
||||||
-name : string
|
-string name
|
||||||
}
|
}
|
||||||
Student "1" --o "1" IdCard : carries
|
Student "1" --o "1" IdCard : carries
|
||||||
Student "1" --o "1" Bike : rides
|
Student "1" --o "1" Bike : rides
|
||||||
@@ -604,11 +606,11 @@ classDiagram
|
|||||||
}
|
}
|
||||||
class IdCard{
|
class IdCard{
|
||||||
-id : int
|
-id : int
|
||||||
-name : string
|
-string name
|
||||||
}
|
}
|
||||||
class Bike{
|
class Bike{
|
||||||
-id : int
|
-id : int
|
||||||
-name : string
|
-string name
|
||||||
}
|
}
|
||||||
Student "1" --o "1" IdCard : carries
|
Student "1" --o "1" IdCard : carries
|
||||||
Student "1" --o "1" Bike : rides
|
Student "1" --o "1" Bike : rides
|
||||||
|
Reference in New Issue
Block a user