Object diagrams: instance snapshots

Object diagrams: instance snapshots

puml.online

简介 / 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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@startuml
object "Alice (ID:001)" as A {
name = Alice
role = Admin
active = true
}
object "Bob (ID:002)" as B {
name = Bob
role = Editor
active = false
}
object "Order #20261020" as O {
id = 20261020
status = shipped
}

A --> O : places
B --> O : reviews
@enduml

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
2
3
4
5
6
7
8
9
10
11
12
13
14
classDiagram
class User {
+String name
+String role
+Boolean active
}
class Order {
+Integer id
+String status
}
User "2" o-- "1" Order : places
User "1" ..> "1" Order : reviews
note for User "Alice(role=Admin)\nBob(role=Editor)"
note for Order "id=20261020\nstatus=shipped"

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.