×

Index

Software Engineering Tutorial

Discrete Mathematics Tutorial

Digital Electronics Tutorial

Class diagram in Unified Modeling Language (UML)

In this tutorial, we will learn about the class diagram in unified modeling language (UML). By Monika Sharma Last updated : April 05, 2023

What is a Class?

Classes are used to represent the object-oriented models. As we know that in the OOPs structure, every entity is treated as an object. A class thus can be defined as a collection of objects that share the common properties and behavior.

Class Diagram

The Class diagram of the software consists of all the classes that exist in the software. In the class diagram, a class is represented via a rectangular box. Each of the classes is divided into three sections. The topmost section consists of the class name. The second section consists of the names of all the attributes that the class contains with their data types. And the third section consists of the methods (or functions) that are defined in the class. (It must be noted that the section of attributes and methods can be empty, but the class name cannot.)

Class Diagram Example 1

For example: Consider a class named "books" which has some attributes and methods. The class diagram for this very class would look something like this:

The class diagram in SE (1)

Here, Books is the name of the class, which has the following attributes: BookId of integer type, BookCategory of String type, NumberOfBooks of integer type, and has two methods namely: AddBook() and AlterNumberOfBooks().

Now, the class diagram not only consists of the classes, but these classes also hold some relation with each other, and this relation is also represented in this diagram.

A class is connected with another class (with whom it holds a relation) using a single line, and on that line, we represent the cardinality. The cardinality represents the number of entities that exist in the relation. It may be one to one, one to many, etc. The cardinality symbols are represented as follows for a class:

The class diagram in SE (2)

Image source: https://wcs.smartdraw.com/class-diagram/img/notes.jpg?bn=1510011152

Class Diagram Example 1

Let us consider the example of the library management system. The following is the class diagram for the same.

It consists of nine classes that are interconnected. The relations and cardinality of each of them can also be inferred from the class diagram itself.

The class diagram in SE (3)

Class Diagram for library management System




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.