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.
Important Topics for the 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.
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.
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.
The object diagram in UML uses specific notations to represent instances of classes and their relationships at a particular moment in time.
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.
Inside the object box, attributes of the object are listed along with their specific values.
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.
For Example – In the figure below, an object of class Student is linked to an object of class College.
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.
For example – In the figure below, an object of Player class is dependent (or uses) an object of Bat class.
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.
For example – The object of Order class is associated with an object of Customer class.
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.
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.
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.
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.
The main purpose of using object diagrams is:
Object diagrams in UML also play a crucial role in various phases of software development. Here are some use cases for object diagrams: