Class diagrams: packages and namespaces
简介 / Introduction
Class diagrams don’t just show relationships — they also use packages or namespaces to organize model elements into a hierarchical structure. This article uses the same scenario to compare PlantUML and Mermaid’s package/namespace syntax, highlighting similarities and differences.
PlantUML 版
1 | package "com.example.app" { |
PlantUML uses package "name" { ... } to group classes, supports nesting and colors/icons, and expresses dependencies with arrows.
Mermaid 版
1 | classDiagram |
Mermaid uses namespace 名称 { ... } to separate classes under the same namespace. Class bodies can optionally declare member methods, and dependency arrows work the same way.
对比 / Side-by-side
| Feature | PlantUML | Mermaid |
|---|---|---|
| Package/namespace keyword | package "name" { } |
namespace name { } |
| Class member syntax | Just class ClassName in block |
Requires +method() inside class body |
| Nested packages | Supported, multi-level package nesting |
Not directly supported; simulate with namespace hierarchy |
| Dependency arrows | --> / ..> / `< |
–` |
| Colors / icons | Supported via package "name" #Pink |
Not supported |
小结 / Wrap-up
PlantUML’s package syntax is richer — it supports nesting, colors, and icons, making it better suited for formal modeling. Mermaid’s namespace is lighter and more readable, ideal for documentation and quick diagrams. Dependency arrow syntax is nearly identical between the two, keeping the learning curve low.
- Title: Class diagrams: packages and namespaces
- Author: puml.online
- Created at : 2026-09-03 09:00:00
- Updated at : 2026-09-03 01:06:42
- Link: https://puml.online/blog/class-diagram-packages-en/
- License: This work is licensed under CC BY-NC-SA 4.0.