Object Diagrams  «Prev  Next»
Lesson 3Object diagram notation
ObjectiveCompare and contrast the object diagram and the class diagram notation.

Object Diagrams vs. Class Diagrams: A Comprehensive Examination for Object Modelers

In Unified Modeling Language (UML), object diagram notation and class diagram notation are closely related but have distinct purposes and representations. Here's a detailed comparison:
Object Diagram Notation
  1. Purpose:
    • Represents a snapshot of the system at a specific point in time.
    • Shows instances (objects) of classes and their relationships.
  2. Key Features:
    • Focuses on actual instances with specific data values.
    • Highlights objects, links, and their states.
    • Provides a detailed view of how a system's elements interact at runtime.
  3. Elements:
    • Objects: Instances of classes, depicted as rectangles with the format objectName:ClassName. The objectName is optional.
    • Links: Connections between objects, represented as solid lines.
    • Attributes: Shows specific values of attributes for the instances.
  4. Use Cases:
    • Debugging runtime issues.
    • Illustrating real-world examples of class relationships.
    • Explaining complex system behavior with concrete examples.
  5. Example:
    • An instance of a Person class named John might be shown as:
      John:Person
      age = 30
      address = "123 Elm Street"
              
Class Diagram Notation
  1. Purpose:
    • Provides a blueprint of the system.
    • Shows classes, their attributes, methods, and relationships at a type level.
  2. Key Features:
    • Focuses on the static structure of the system.
    • Highlights types and relationships rather than specific instances.
    • Useful for system design and architecture.
  3. Elements:
    • Classes: Represented as rectangles divided into three compartments:
      • Top: Class name.
      • Middle: Attributes (e.g., name: String).
      • Bottom: Methods (e.g., getName(): String).
    • Relationships:
      • Associations, generalizations, dependencies, compositions, and aggregations.
      • Visibility: Can indicate public (+), private (-), or protected (#) access levels.
  4. Use Cases:
    • Planning system architecture.
    • Understanding static relationships between components.
    • Communicating high-level system design to stakeholders.
  5. Example:
    • A Person class might be shown as:

         +------------------------+
         | Person                 |
         +------------------------+
         | -name: String          |
         | -age: int              |
         +------------------------+
         | +getName(): String     |
         | +setAge(age: int): void |
         +---------------------+
         

Comparison
Feature Object Diagram Class Diagram
Focus Runtime instances and their states. Static structure of the system.
Abstraction Level Instance-level (concrete). Class-level (abstract).
Relationships Links between objects. Associations, inheritance, composition, etc.
Purpose Shows real-time scenarios. Provides a design blueprint.
Elements Objects and their values. Classes, attributes, and methods.

Contrast
  • Time Perspective: Object diagrams show a snapshot of the system's state during execution, while class diagrams represent a timeless design blueprint.
  • Granularity: Object diagrams are specific to individual instances, whereas class diagrams are generic and apply to all instances of a class.
  • Dynamic vs. Static: Object diagrams are dynamic and context-specific, while class diagrams are static and context-independent.

By using these diagrams together, you can bridge the gap between high-level design and detailed runtime behavior.

The object diagram notation is largely a subset of the class diagram notation. The graphics below show examples of an object and a class for the object.
Class diagram
The image shows two class diagrams for the classes `Employee` and `Address`.
1) Data Members
  • Employee Class
    • employeeid: integer = 0
    • first_name: char = blank
    • last_name: char = blank
  • Address Class
    • streetline1: char = blank
    • streetline2: char = blank
    • city: char = blank
    • statecode: char = blank
    • zipcode: numeric = 0
    • addresstype: char = blank
  • 2) Functions
    • Employee Class
      • setEmployeeID()
      • getEmployeeID()
      • setFirstName()
      • getFirstName()
      • setLastName()
      • getLastName()
      • setAddress()
      • getAddress()
    • Address Class
      • setStreetLine1()
      • setStreetLine2()
      • setCity()
      • setStateCode()
      • setZipCode()
      • getStreetLine1()
      • getStreetLine2()
      • getCity()
      • getStateCode()
      • getZipCode()

These extracted details represent the structure of the `Employee` and `Address` classes as depicted in the UML class diagram. Class diagram

Object diagram
Object diagram

Note the differences between the two diagrams:
Class diagram Object diagram
The class has three compartments: name, attribute, and operation. The object has only two compartments: name and attribute.
The class name stands alone in the class name compartment. The format for an object name is object name, colon, class name (Tom : Employee). You will encounter this notation in other diagrams that model objects rather than classes.
Sometimes the object name is left off and only the colon and class name are used. This is referred to as an anonymous object.
The class attribute compartment defines the properties of the attributes. The object defines only the current value of each attribute.
Operations are listed in the class. Operations are not included in the object because they would be identical for every object of the same class.
The classes are connected with an association with a name and multiplicity. The objects are connected with a link that has a name and no multiplicity. Classes represent a "classification" of objects, so it is necessary to specify how many mayparticipate in the association. Objects represent single entities. All links are one to one, so multiplicity is irrelevant. Roles may be used on links and associations.

In the next lesson, you will learn how to use the object diagram for testing and verification.

Object Diagram Notation versus class Diagram Notation - Quiz

Click the Quiz link below to take a short quiz about the material we've just covered.
Object Diagram versus Class Diagram - Quiz

SEMrush Software