The key difference between class diagram and object diagram is that the class diagram represents the classes and their relationships between them while the object diagram represents the objects and their relationships between them at a particular moment.
UML stands for Unified Modelling Language. It helps to model the object-oriented concepts to develop software solutions. UML diagrams provide various advantages such as understanding business requirements and to get a high-level understanding of the system functionalities. There are two main UML modelling types. They are structural modelling and behavioral modelling. Structured modeling describes the static features of the system. On the other hand, behavioral modeling describes the dynamic nature of the system. The class diagram and object diagram are two structural modeling UML diagrams.
CONTENTS
1. Overview and Key Difference
2. What is Class Diagram
3. What is Object Diagram
4. Side by Side Comparison – Class Diagram vs Object Diagram in Tabular Form
5. Summary
What is Class Diagram?
A class diagram represents a static view of the system. It describes the attributes and operations of classes. Class diagrams are the most widely used modeling diagram for object-oriented systems because they can be directly mapped with object-oriented languages.
Above is a simple example of a class diagram. It is an online ordering system. User, Customer, Administrator, Order, OrderDetails are classes. Each class consist of attributes and methods. Attributes describe the properties while methods describe the behaviors or operations.
In a class diagram, a rectangle represents the class. It further divides into three sections. The top section is to write the name of the class. The middle section is for attributes, and the last section is for methods. The Customer class has attributes such as name, address, email, customerId, accountBalance and methods such as register, login and purchase.
Attributes and Methods
The attributes and methods have a symbol to indicate the visibility. The – represents private. The other classes cannot access the private members. They are visible only to that specific class. The + represents public and other classes can access those members. Usually, the class attributes are private, and the methods are public. There is another visibility. This is called protected, and # symbol represent it. Only the same class and sub class members can access the protected members.
The User is the generalized form of Administrator and Customer. These two classes can have the attributes and methods of the user class as well as their own attributes and methods. The User class is the parent class while the Customer and Administrator classes are the child classes. This concept is called Generalization.
The Customer and Order have the composition relationship. The Order class cannot exist without the Customer class. The Order and OrderDetails have the composition relationship. Therefore, the OrderDetails class cannot exist without the Order class.
The class diagram also represents multiplicity. When referring to the Customer and Order relationship, the customer can have zero or many orders. On the other hand, an order only belongs to one customer. The order and OrderDetails have 1 to 1 relationship. An Order can have only one OrderDetails. Those are some basics of Class Diagrams.
What is Object Diagram?
Another structural diagram is an object diagram. It is similar to a class diagram, but it focuses on objects. The basic concepts of object diagram are similar to a class diagram. These diagrams help to understand object behavior and their relationships at a particular moment.
The s1, s2, and s3 are student objects, and they enroll to c1 course object. The l1 lecturer object teaches the course c1. The lecturer object l2 teaches the special course c2. The Student s3 enrolls to c1 course as well as c2 special course. This diagram illustrates how a set of objects relates to each other. Overall, an object diagram represents the static view of a system but specifically, it represents a static view of the system at a particular moment.
What is the Difference Between Class Diagram and Object Diagram?
A class diagram is a type of static structural diagram that describes the structure of the system by showing the classes, their attributes, methods and the relationship among the classes. An object diagram is also a type of static structural diagram that shows a complete or partial view of the structure of a modeled system at a specific time.
Furthermore, class diagrams define classes and show how they relate to each other. Object diagrams show the objects and their relationships. Classes are the blueprints and objects are the instances of classes. This is the main difference between class diagram and object diagram.
Further, in a class diagram, the class name starts with uppercase. e.g., Student. In an object diagram, the object name is in lowercase, and it is underlined. e.g., s1: Student
Summary – Class Diagram vs Object Diagram
Both class and object diagrams represent static features of a system. The difference between class diagram and object diagram is that class diagram represents the classes and their relationships between them while object diagram represents the objects and their relationships between them at a particular moment. These diagrams help to get a high-level understanding of the system.
Reference:
1.“Unified Modeling Language (UML) | Object Diagrams.” GeeksforGeeks, 13 Feb. 2018. Available here
2.Tutorials Point. “UML – Class Diagram.” Tutorials Point, 8 Jan. 2018. Available here
3.Tutorials Point. “UML – Object Diagrams.” Tutorials Point, 8 Jan. 2018. Available here
Leave a Reply