Object diagram

An object diagram is a snapshot of system objects at some point in time. Because it shows instances, not classes, an object diagram is often called an instance diagram.

It is used to document data structures and create static snapshots of the state of objects, taking into account real instances or prototypes.

The dynamics of the behavior of objects is usually depicted as a sequence of such diagrams.

1. Basic elements 

An object is an instance of a class. 

An object, like a class, is indicated by a rectangle, but its name is underlined. Name is the name of the object and the name of its class, separated by a colon. To indicate the values of the attributes of an object, a special section may be provided in its designation.

An object can be anonymous: this is necessary if at the moment it does not matter which object of this class takes part in the interaction.

Relations between objects: 

  • Extension 
  • Compjsition 
  • Aggregation 

2. Syntax

Object declaration is done using the keyword object:

Код скопирован
  • @startuml
    object firstObject
    object “My Second Object” as o2
    @enduml

To declare Object attributes (fields) the colon symbol : should be used followed by Attribute name:

Код скопирован
  • @startuml
    object user
    user : name = “Dummy”
    user : id = 111
    @enduml

Also, it is possible to put all fields inside curl brackets {}:

Код скопирован
  • @startuml
    object user {
    name = “Dummy”
    id = 123
    }
    @enduml

Relations between objects are determined using the following symbols: 

Type Symbol 
Extension <|– 
Composition *– 
Aggregation o– 

It is possible to replace -- with .. to get a dashed line. 

Also you can add a description to the link using a colon : followed by the description text. You can use double quotation marks "" on each side of the link to determine the number of elements.

Knowing these rules, you can create the following diagrams.

Код скопирован
  • @startuml
    object Object01
    object Object02
    object Object03
    object Object04
    object Object05
    object Object06
    object Object07
    object Object08
    Object01 <|– Object02
    Object03 *– Object04
    Object05 o– “4” Object06
    Object07 .. Object08 : some labels
    @enduml

You can use packages to group objects. It can be defined using the package keyword, with the possibility to declare its background color using the html color code or its name.

Код скопирован
  • @startuml package “Collections” #8888 {
    object Object01
    object Object02
    object Object03
    object Object04
    object Object05
    object Object06
    object Object07
    object Object08
    Object01 <|– Object02
    Object03 *– Object04
    Object05 o– “4” Object06
    Object07 .. Object08 : some labels
    }
    @enduml