Object Diagrams | Unified Modeling Language (UML)

Object diagrams are a visual representation in UML (Unified Modeling Language) that illustrates the instances of classes and their relationships within a system at a specific point in time. They display objects, their attributes, and the links between them, providing a snapshot of the system’s structure during execution. Since object diagrams depict behavior when objects have been instantiated, we can study the behavior of the system at a particular instant.

Object-diagram-uml

Important Topics for the Object Diagrams

1. What are Object Diagrams?

An Object Diagram can be referred to as a screenshot of the instances in a system and the relationship that exists between them.

Object diagrams in UML are depicted using a simple and intuitive notations to show a snapshot of a system at a specific point in time, displaying instances of classes and their relationships.

What is an Object?

An object refers to a specific instance of a class within a system. A class is a blueprint or template that defines the common attributes and behaviors shared by a group of objects. An object, on the other hand, is a concrete and individual occurrence of that class, possessing unique values for its attributes.

What is a Classifier?

In UML a classifier refers to a group of elements that have some common features like methods, attributes and operations. A classifier can be thought of as an abstract metaclass which draws a boundary for a group of instances having common static and dynamic features.

For example:

we refer a class, an object, a component, or a deployment node as classifiers in UML since they define a common set of properties. We are able to design object diagrams by instantiating classifiers.

4. Object Diagram Notations

The object diagram in UML uses specific notations to represent instances of classes and their relationships at a particular moment in time.

Object-Diagram-Notations-222

1. Objects or Instance specifications

When we instantiate a classifier in a system, the object we create represents an entity which exists in the system. We can represent the changes in object over time by creating multiple instance specifications. We use a rectangle to represent an object in an object diagram.

object-box

2. Attributes and Values

Inside the object box, attributes of the object are listed along with their specific values.

3. Link

We use a link to represent a relationship between two objects. We represent the number of participants on the link for each, at the end of the link. The term link is used to specify a relationship between two instance specifications or objects. We use a solid line to represent a link between two objects.

links

For Example – In the figure below, an object of class Student is linked to an object of class College.

An-object-diagram-using-a-link-and-3-objects---(2)

4. Dependency Relationships

We use a dependency relationship to show when one element depends on another element. A dependency is used to depict the relationship between dependent and independent entities in the system.

Dependency-Relationship-notation

For example – In the figure below, an object of Player class is dependent (or uses) an object of Bat class.

An-object-diagram-using-a-dependency-An-object-diagram-using-a-dependency--(1)

5. Association

Association is a reference relationship between two objects (or classes). An association line connects two object boxes, representing a relationship between instances of two classes. We use association when one object references members of the other object. Association can be uni-directional or bi-directional. We use an arrow to represent association.

Association-2

For example – The object of Order class is associated with an object of Customer class.

An-object-diagram-using-association---(1)

6. Aggregation

Aggregation represents a “has a” relationship. We use a hollow diamond on the containing object with a line which joins it to the contained object.

Aggregation

For example – A library has an aggregation relationship with books. Library has books or books are a part of library. The existence of books is independent of the existence of the library.

An-object-diagram-using-aggregation---(2)

7. Composition

Composition is a type of association where the child cannot exist independent of the other. We use a filled diamond on the containing object with a line which joins it to the contained object. Composition is also a special type of association. It is also a kind of parent child relationship but it is not inheritance. So whenever independent existence of the child is not possible we use a composition relationship.

composition-diagram

Consider the example of a boy Gurkaran: Gurkaran is composed of legs and arms. Here Gurkaran has a composition relationship with his legs and arms. Here legs and arms can’t exist without the existence of their parent object.

An-object-diagram-using-composition----(1)

5. Purpose of Object Diagrams

The main purpose of using object diagrams is:

6. Benefits of Object Diagrams