Object Diagram in UML

Introduction

If a Class Diagram is the blueprint, the Object Diagram is the photograph. It captures a snapshot of a system at a particular moment in time — complete with real data and actual object instances. Where class diagrams deal with potential structure, object diagrams make it real.

In this tutorial, we’ll explore the world of object diagrams using real-life examples, especially from a familiar setting — a school. We'll see how students, teachers, and subjects come to life as objects in a diagram. By the end, you’ll not only understand object diagrams, but you’ll know exactly when and how to use them in your software designs.

What is an Object Diagram?

An Object Diagram in UML represents a concrete instance of a class diagram. It shows a snapshot of the system — actual objects, their attribute values, and how they relate to one another — at a specific point in time.

Object diagrams are useful for:

  • Testing object interactions
  • Debugging system behavior
  • Modeling complex object relationships
  • Demonstrating real scenarios to stakeholders
Basic object diagram concept: objects and links

Class Diagram vs Object Diagram

Aspect Class Diagram Object Diagram
Focus Classes and structure Objects and data
Nature Blueprint (abstract) Snapshot (concrete)
Usage Design-time Runtime analysis/testing
Includes Attributes, methods, relationships Object names, values, links

Notation of Object Diagram

Each object is represented as a rectangle with:

  • Object Name: in the form objectName : ClassName
  • Attributes: listed with current values
ravi : Student
-----------------------
name = "Ravi"
rollNumber = 101

Links between objects are shown as solid lines, similar to associations in class diagrams.

Notation for object with attributes and links

Example: School Scenario

Step 1: Class Diagram (Reference)

Class Student {
  name : String
  rollNumber : int
}

Class Teacher {
  name : String
  subject : String
}

Class Subject {
  title : String
  teacher : Teacher
}
Class diagram of Student, Teacher, Subject

Step 2: Object Diagram Snapshot

Let’s say it’s a weekday morning and Ravi (a student) is attending Math class taught by Ms. Sharma. Here’s how that would look in an object diagram:

ravi : Student
-----------------------
name = "Ravi"
rollNumber = 101

math : Subject
-----------------------
title = "Mathematics"

sharma : Teacher
-----------------------
name = "Ms. Sharma"
subject = "Mathematics"

Relationships are shown as links:

  • ravi is enrolled in math
  • math is taught by sharma
Object diagram of school scenario showing links between objects

How to Draw an Object Diagram: Step-by-Step

Step 1: Identify Classes and Create Instances

Start from a class diagram. Create specific instances of classes (e.g., ravi : Student, math : Subject).

Step 2: Assign Attribute Values

Populate object attributes with actual values to represent a moment in the system.

Step 3: Define Object Links

Show connections between objects (e.g., which subject a student is enrolled in, which teacher teaches it).

Step 4: Use Standard Notation

Follow UML syntax. Show object names with their class, underline the object label (optional), and use solid lines for links.

Use Cases of Object Diagrams

1. Debugging

Helps visualize runtime issues by showing actual objects and their current values. For example, why a student’s marks list is empty?

2. Test Scenarios

Used in unit testing and simulations to show expected object configurations before and after execution.

3. Classroom Learning

Perfect for teaching object-oriented concepts. Students can relate class-to-object transitions intuitively.

4. Explaining Flows

Non-technical stakeholders understand concrete data and relationships better than abstract class diagrams.

Best Practices

  • Keep it focused: Show only relevant objects for clarity.
  • Label clearly: Use descriptive object names (e.g., ravi : Student).
  • Use real data: Populate attributes with realistic values.
  • Align with class diagram: Ensure object structure matches class definitions.

Tools for Drawing Object Diagrams

  • StarUML: Easily switch between class and object diagrams.
  • Lucidchart: Offers real-time collaboration and templating.
  • PlantUML: Great for textual UML generation.
  • draw.io: Fast and intuitive for beginners.
@startuml
object ravi : Student {
  name = "Ravi"
  rollNumber = 101
}

object math : Subject {
  title = "Mathematics"
}

object sharma : Teacher {
  name = "Ms. Sharma"
  subject = "Mathematics"
}

ravi -- math
math -- sharma
@enduml
PlantUML generated object diagram example

Conclusion

Object diagrams take your design from theory to reality. They help you see how the parts of your system actually look when the program is running. Especially for Java developers, being able to relate Java objects to UML object diagrams can improve your understanding of how classes come to life in memory.

As you build more complex systems, object diagrams can guide your debugging, testing, and planning phases with clarity and precision. Start by taking any class diagram you’ve built and create an object diagram version of it — you’ll immediately notice how much more grounded your understanding becomes.

In the next lesson, we’ll move from structural to behavioral diagrams — starting with the Use Case Diagram, which helps define how users interact with your system.

QUIZ

Question 1:What is the primary purpose of an object diagram in UML?

Question 2:Object diagrams are used to show potential behavior over time.

Question 3:Which of the following are typical elements found in an object diagram?

Question 4:Which of these best illustrates the difference between a class diagram and an object diagram?

Question 5:An object diagram can show multiple instances of the same class with different attribute values.

Question 6:When is it most useful to create an object diagram?

Question 7:What notation does UML use to represent an object in an object diagram?

Question 8:Object diagrams cannot be used to verify multiplicity constraints defined in class diagrams.

Question 9:In a school management object diagram, you see:
mathTeacher : Teacher
room101 : Classroom
mathTeacher -- room101
What does this represent?