overview of the main types of diagrams, object diagram. Part 3
Object Diagram
Object Diagram is a structure diagram that shows objects, their attributes, and relationships with other objects.
An object is an instance of a class at a particular point in execution time that can have its own state and data values.
A UML object diagram is an instance of a class diagram (I previously wrote about a class diagram here), it shows a snapshot of the detailed state of a system at a specific point in time.
Thus, it can be said that An object diagram is a special case of a class diagram.
When to use an object diagram?
The use of object diagrams is quite limited.
During the design analysis phase, you can create a class diagram to describe the structure of the system, and then create a set of object diagrams as test cases to verify the accuracy and completeness of the class diagram.
Before creating a class diagram, you can create an object diagram to learn facts about specific model elements and their relationships, or to illustrate specific examples of needed classifiers.
What elements does an object diagram consist of?
Objects
Each object is represented by a rectangle in which the object's name and class are underlined and separated by a colon.
Object Attributes
Similar to a class diagram, each object is assigned attributes. However, unlike classes, object attributes must be assigned values because in a class diagram we are looking at a specific time period.
Connections
Relationships are used to represent the relationship between two objects (similar to a class diagram).
Class Diagram VS Object Diagram
Below are the main points about class diagrams and object diagrams:
An object diagram is a UML structure diagram that shows instances of classifiers in models.
Object diagrams use similar notation to that used in class diagrams.
Class diagrams show the actual classifiers and their relationships in the system.
Object diagrams show specific instances of these classifiers and the relationships between these instances at a specific point in time.
The picture below shows an example of a class diagram and an object diagram for this class. As you can see, both diagrams are very similar and the second is a special case of the first.
How to draw an object diagram?
When modeling an object diagram, it is worth considering that the object diagram must be a valid instance of a static class diagram.
Below are the steps to model an object diagram.
The first step is to define the mechanism you would like to model. A mechanism represents some functionality or behavior of a part of the system you are modeling that results from the interaction of many classes, interfaces, and other things.
For each mechanism, you need to define the classes, interfaces, and other elements that participate in this interaction; You also need to define the relationships between these elements.
Next we need to consider one scenario that goes through this mechanism. Freeze this scenario at a specific point in time and visualize each object involved in the mechanism.
If necessary, you need to provide information about the state and attribute values of each such object to understand the scenario.
Conclusion
So, today we looked at an object diagram, got acquainted with its main elements, and also understood how it differs (and how it is similar) from a class diagram.
To summarize, I want to say that:
An object diagram is a special case of a class diagram. It shows a snapshot of the detailed state of the system at a specific point in time.
An object diagram consists of almost the same set of entities as a class diagram: objects, object attributes and relationships
The use of object diagrams is quite limited. One example of the use of a diagram is to create a class diagram to describe the structure of a system, and then create a set of object diagrams as test cases to verify the accuracy and completeness of the class diagram.
Thanks to everyone who read this article to the end. Share your opinion in the comments. In the next article I will continue the topic of process modeling in UML notation and will analyze a new type of diagram.