Advertisement
❮ Previous: Mermaid State Diagrams Next: Mermaid ER Diagrams ❯

Mermaid Class Diagrams

Class diagrams model object-oriented structures.

They can show:


Basic Class Syntax

classDiagram
    class User {
        -String username
        -String password
        +login() boolean
        +updateProfile() void
    }

Try this code ❯


Visibility

Common visibility symbols:

Symbol Meaning
+ Public
- Private
# Protected

Relationships

Common relationships include:

Syntax Meaning
`< --`
*-- Composition
o-- Aggregation
--> Association
..> Dependency
`.. >`
-- Solid link
.. Dashed link

Relationship Example

classDiagram
    Animal <|-- Dog
    Animal <|-- Cat
    Car *-- Engine
    Library o-- Book

    class Animal {
        +int age
        +makeSound()
    }

Try this code ❯


Small Library Example

classDiagram
    class Library {
        +String name
    }

    class Book {
        +String title
    }

    Library "1" o-- "*" Book : contains

Try this code ❯

❮ Previous: Mermaid State Diagrams Next: Mermaid ER Diagrams ❯
Advertisement