Relationships in Class Diagram
There are three types of relationships in UML:
- Dependency: Dependency is a semantic link between two or more classes in which modifications in one class affect changes in the other. It results in a relationship that is weaker.
Employee_Name is dependent on Employee_Id in the following example.

- Generalization: A relationship between a parent class (superclass) and a child class is known as a generalization (subclass). The parent class is inherited by the child class in this case.
The generic form of a Bank_Account, for example, is a Current_Account, a Savings_Account, and a Credit_Account.

- Association: A static or physical relationship between two or more items is referred to as an association. It indicates the number of items in the connection.
A college, for example, is linked to a department.

Multiplicity: It specifies the maximum number of occurrences of an attribute that can be used. If no range is supplied, one is assumed to be the default multiplicity.
Multiple patients, for example, are admitted to one hospital.

Aggregation: An aggregation is a subset of associations that denotes the existence of a relationship. It has a higher level of specificity than association. A part-whole or part-of connection is defined by this term. The kid class can exist independently of its parent class in this type of connection.
The firm employs a large number of people, and even if one of them leaves, the company will continue to exist.

Composition: Aggregation is a subset of composition, which is a subset of composition. It depicts the parent's and child's interdependence, implying that if one component is removed, the other is also removed. It symbolises the link between the whole and the parts.
A contact book contains many contacts, and deleting the contact book will result in the loss of all contacts.

The drawing of class diagram
The most common UML diagrams used for software application development are class diagrams. It is critical to understand the class diagram design technique.
Class diagrams have a lot of properties to consider while creating them, but we'll look at them from the top down.
A class diagram is a graphical representation of the system's static view that depicts many application components. A series of class diagrams represent the entire system.
When constructing a class diagram, keep the following points in mind:
- The name of the class diagram should be descriptive of the system's features.
- Each component, as well as its relationships, should be identified ahead of time.
- Each class's responsibility (attributes and methods) should be explicitly defined.
- A minimal amount of attributes should be stated for each class since having too many properties can confuse the diagram.
- If you need to discuss a specific diagram element, take notes. The developer/coder should understand the drawing in the end.
- Finally, the diagram should be sketched on plain paper and modified as many times as possible before producing the final version.
A Food Order System of an application is depicted in the figure below. It refers to a specific feature of the overall programme.
- First and foremost, the system's two parts are recognised as FoodOrder and Customer. Because a consumer may place several orders, they have a one-to-many connection.
- The FoodOrder class is an abstract class with two concrete classes, SpecialFoodOrder and NormalFoodOrder, that inherit (inheritance relationship).
- All of the FoodOrder class attributes are shared by the two inherited classes. They also contain extra features such as dispatchFood() and receiveFood().
The following class diagram was created with all of the principles listed above in mind.

Use of Class Diagrams
A class diagram is a static diagram representing a system's fixed perspective. The system's vocabulary is described in the static view.
The component and deployment diagrams are built on top of the class diagram. Class diagrams are used to create executable code for forward and reverse engineering of any system and depict the static perspective of the system.
The class diagram is an exception to the rule that UML diagrams are not immediately transferred to object-oriented programming languages.
The class diagram easily shows the mapping with object-oriented languages like Java, C++, and others. Class diagrams are commonly utilised for building purposes, based on my own experience.
In a nutshell, class diagrams are used for the following purposes:
- Describes the system's static perspective.
- Showing how the pieces of the static view work together.
- Defining the functions that the system does.
- Object-oriented programming languages are used to create software applications.
Advantages
Here are some advantages of making a class diagram which is given below:
- For complicated systems, it can represent the object model.
- It cuts down on maintenance time by giving you a visual representation of how an application is structured before you start writing.
- It shows a generic diagram of an application to help you understand it better.
- It depicts a detailed chart by emphasising the code that needs to be developed.
-
It is beneficial to both developers and stakeholders.
Read more about Software Engineering here.
A Class Diagram's Crucial Elements
The class diagram is divided into three parts:

Upper Part
The upper section includes the class name. A class is a group of related objects with the same relationships, characteristics, methods, and meanings. The following are some of the rules to consider while representing a class:
- The first letter of the class name should be capitalised.
- Place the class name in the upper section's centre.
- The name of the class must be stated in capital letters.
- Italics should be used to write the abstract class's name.
Middle Part
The properties that characterise the class's quality are found in the middle section. The following are the features of the attributes:
The public (+), private (-), protected (#), and package (~) visibility factors are specified with the characteristics.
The visibility factors demonstrate the accessibility of an attribute class.
The property should be given a meaningful name that explains how it is used within the class.
Lower Part
Methods or procedures are found in the lower section. The methods are listed in a list format, with each technique placed on a separate line. It shows how a class interacts with information.
Also see, Adhoc Testing
FAQs
-
What is UML?
It's a general-purpose modelling language used to show how the system works. It's a graphical language used in the software industry for describing, visualising, building, and documenting software system artefacts and business modelling.
-
Define class diagram.
The class diagram depicts a static representation of an application. It shows the many sorts of things that may be found in the system and their relationships. A class comprises its objects, but it can also inherit from other classes. A class diagram represents, explains, and records numerous parts of a system and creates executable software code.
-
Write any one advantage of the class diagram?
It simplifies complex programme design and incorporates OOPs, a commonly utilised idea.
-
What are the important sections of the class diagram? Name them.
There are three sections in a class diagram which are mentioned below:
Upper: The upper section includes the class name.
Middle: The properties that characterise the class's quality are found in the middle section.
Lower: Methods or procedures are found in the lower section.
-
Define an object diagram in UML.
Object diagrams are formed from class diagrams, they are reliant on class diagrams.
A class diagram is represented by an object diagram. Class and object diagrams have identical fundamental notions. Object diagrams also depict a system's static perspective, but this view is a snapshot of the system at a certain point in time.
Key Takeaways
We have discussed the class diagram in this article. We have discussed its benefits and usages. We have also discussed how do we make class diagrams. The primary goal of class diagrams is to create a static representation of an application. This one is the only construction diagram mapped using object-oriented programming languages.
For getting started with object-oriented software design, visit the topic Object Diagram.
But before going further, you should understand the basics of OOPs, which you can learn for free by visiting here- Learn OOPS in data structures in Python for free | Coding Ninjas and do not forget to visit our library section where you can learn many topics related to OOPS.
Happy Learning!