Mermaidでクラス図を書く
以下のコード例では省略しているが、1行目にclassDiagramと書く必要がある
docs
2022/9/8現在Noteを書く記法がないらしいmrsekut.icon
https://github.com/mermaid-js/mermaid/issues/1414
code:mermaid
class BankAccount
BankAccount : +String owner
BankAccount : +Bigdecimal balance
BankAccount : +deposit(amount)
BankAccount : +withdrawal(amount)
https://gyazo.com/c68175e16461aed5ec6cf4afddf7398b
class名
property
method
classの定義方法は2種類
明示的に定義する
code:mermaid
class Animal
まず関係を書いちゃう
code:mermaid
Vehicle <|-- Car
property,methodの紐付け方は2種類
出力は同じ
classとpropetyの定義を一緒に書く
記述量が少ない
code:mermaid
class BankAccount{
+String owner
+withdrawal(amount)
}
classの定義と、propertyの定義を別の場所にかける
code:mermaid
class BankAccount
BankAccount : +String owner
BankAccount : +withdrawal(amount)
型の書き方
返り値の型
code:mermaid
class BankAccount{
+String owner
+withdrawal(amount) int
}
generics
https://mermaid-js.github.io/mermaid/#/classDiagram?id=generic-types
Visiblity
https://mermaid-js.github.io/mermaid/#/classDiagram?id=visibility
+ Public
- Private
# Protected
~ Package/Internal
関係
クラス図の矢印
関係にラベルを付ける
code:mermaid
classA --|> classB : 継承
双方この関係
https://mermaid-js.github.io/mermaid/#/classDiagram?id=two-way-relations
table:-
<| Inheritance
* Composition
o Aggregation
Association
< Association
|> Realization
多重度
https://mermaid-js.github.io/mermaid/#/classDiagram?id=cardinality-multiplicity-on-relations
1
0..1
1..*
*
n
0..n
1..n
code:mermaid
Customer "1" --> "*" Ticket
Student "1" --> "1..*" Course
Galaxy --> "many" Star : Contains
enum
code:mermaid
class Color{
<<enumeration>>
RED
BLUE
GREEN
WHITE
BLACK
}