Class vs ER diagram: domain modeling

Class vs ER diagram: domain modeling

puml.online

简介 / Introduction

Class diagrams and ER diagrams both describe structured data, but with different focuses: class diagrams target object-oriented design with classes, attributes, and methods; ER diagrams target database design with entities, attributes, and relationships. This post uses the same business scenario to demonstrate both PlantUML and Mermaid syntax, then compares them side by side.

PlantUML 版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@startuml
class User {
-id: Long
-name: String
-email: String
+getName(): String
}
class Order {
-id: Long
-total: BigDecimal
+calculateTotal(): BigDecimal
}
class Product {
-id: Long
-title: String
-price: BigDecimal
}
User "1" --> "*" Order : places
Order "*" --> "*" Product : contains
@enduml

PlantUML uses the class keyword to define class blocks, - for private members, + for public, and (): ReturnType for methods. Relationships use A --> B with multiplicity labels.

Mermaid 版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
classDiagram
class User {
-id: Long
-name: String
-email: String
+getName(): String
}
class Order {
-id: Long
-total: BigDecimal
+calculateTotal(): BigDecimal
}
class Product {
-id: Long
-title: String
-price: BigDecimal
}
User "1" --> "*" Order : places
Order "*" --> "*" Product : contains

Mermaid’s classDiagram uses class with braces for member definitions. Access modifiers use - and + the same way. Relationships use --> with multiplicity; in HTML rendering --> must be escaped as -->.

对比 / Side-by-side

Feature PlantUML Mermaid
Relationship arrow A --> B A --> B
Multiplicity position After arrow "1" --> "*" After arrow "1" -- *"
Method return type +method(): Type +method(): Type
Private member -field -field
Relationship label : label : label

小结 / Wrap-up

Class diagrams suit object-oriented analysis and design, while ER diagrams are better for database schema design. PlantUML has a richer ecosystem for complex projects (skinparam, themes), and Mermaid embeds more easily in Markdown docs and web pages. Knowing both gives you flexibility when communicating designs.

  • Title: Class vs ER diagram: domain modeling
  • Author: puml.online
  • Created at : 2026-10-14 01:00:33
  • Updated at : 2026-10-14 01:07:04
  • Link: https://puml.online/blog/class-vs-er-for-domain-en/
  • License: This work is licensed under CC BY-NC-SA 4.0.