Object diagrams: instance snapshots
简介 / Introduction
An Object Diagram records concrete instances and their attribute values at a specific point in time, serving as a structural snapshot of a class diagram. While class diagrams model abstract types and relationships, object diagrams answer the question: what real instances exist right now and what are their states? PlantUML has a native objectdiagram keyword, while Mermaid approximates it with class diagrams plus notes.
PlantUML 版
1 | @startuml |
PlantUML’s object keyword declares an instance directly, as assigns a shorthand alias, and curly braces hold key = value pairs. Arrows (-->) connect instances; instance labels can be quoted with a display name after the colon.
Mermaid 版
1 | classDiagram |
Mermaid has no dedicated object diagram type; it uses classDiagram with note blocks to attach instance values. Multiplicity labels ("2" / "1") indicate multiple instances of the same class, and property lists show field names.
对比 / Side-by-side
| Feature | PlantUML | Mermaid |
|---|---|---|
| Syntax marker | objectdiagram |
classDiagram |
| Instance declaration | object "label" as alias |
Class itself (note attaches values) |
| Attribute syntax | key = value |
+key: Type (type annotation, not values) |
| Link syntax | --> / -->> |
o-- / ..> |
| Multi-instance | Multiple object blocks |
Class "N" multiplicity label |
| Instance values | Block body: name = Alice |
note for Class |
小结 / Wrap-up
PlantUML’s objectdiagram is the most direct way to express runtime snapshots, ideal for debugging and traceability. Mermaid approximates object diagrams with class diagrams and note annotations, leveraging its unified renderer at the cost of less precise instance representation. Using both together — class diagrams for design, object diagrams for runtime inspection — covers the full modeling lifecycle.
- Title: Object diagrams: instance snapshots
- Author: puml.online
- Created at : 2026-10-20 09:00:00
- Updated at : 2026-10-20 01:07:18
- Link: https://puml.online/blog/object-diagram-instances-en/
- License: This work is licensed under CC BY-NC-SA 4.0.