PlantUML Object Diagram: Runtime Instances
Visualize runtime object instances and their relationships with PlantUML object diagrams. Show concrete values, links between objects, and snapshot states.
Detailed Explanation
Object Diagrams for Runtime Instances
Object diagrams show a snapshot of a system at a specific point in time. Unlike class diagrams which show types, object diagrams show instances with concrete values.
Basic Object Notation
@startuml
title Order #1234 — Snapshot
object "order1234: Order" as order {
orderId = "ORD-1234"
status = "Processing"
createdAt = "2024-03-15T10:30:00Z"
totalAmount = "$149.97"
}
object "item1: OrderItem" as item1 {
lineId = "LI-001"
productName = "Wireless Mouse"
quantity = 1
unitPrice = "$29.99"
}
object "item2: OrderItem" as item2 {
lineId = "LI-002"
productName = "USB-C Hub"
quantity = 2
unitPrice = "$59.99"
}
object "shipping: ShippingInfo" as shipping {
method = "Express"
address = "123 Main St"
estimatedDelivery = "2024-03-18"
}
order *-- item1
order *-- item2
order *-- shipping
@enduml
Naming Convention
Object names follow the UML convention: instanceName: ClassName. The instance name is optional but recommended for clarity. Underlining (which PlantUML renders automatically) distinguishes objects from classes.
When to Use Object Diagrams
Bug Reports: Show the exact state of objects when a bug occurs. This is far more precise than prose descriptions.
Test Documentation: Document the expected state of objects after a test scenario completes.
Design Validation: Create concrete instances to verify that a class diagram design actually works for real data.
Relationships Between Objects
object "user42: User" as u {
name = "Alice"
}
object "cart: ShoppingCart" as c {
itemCount = 3
}
object "session: Session" as s {
token = "abc-xyz"
expiresAt = "2024-03-15T12:00:00Z"
}
u -- c : owns
u -- s : authenticated via
Links between objects use solid lines with optional role labels. Unlike class associations which show possible relationships, object links show actual connections at runtime.
Comparing States
Create two object diagrams side by side to show "before" and "after" states for a state transition, which is invaluable for documenting complex business logic.
Use Case
Creating detailed bug reports with exact object state, documenting test fixtures and expected outcomes, validating domain model designs against real-world data, and explaining complex runtime scenarios during code reviews.