Class Diagram

Alwaz Qazi
3 min readDec 3, 2020

--

UML diagrams are divided into two broad categories

Structure Diagrams

Behavioral Diagrams

Structure Diagrams:

Structure diagrams are used to represent the “Static behavior” of a system. Such as the attributes, features, and how classes and objects are linked with each other. The examples of structure diagrams are listed below:

· Class diagram

· Component diagram

· Deployment diagram

· Object diagram

· Package diagram

· Profile diagram

· Composite structure diagram

Behavioral Diagrams:

Behavioral diagrams are used to show the behavior of a system that how a user will interact with a system and what are the functionalities performed by the system. Different types of behavioral diagrams are listed below:

· Use case diagram

· Activity diagram

· State machine diagram

· Communication diagram

· Sequence diagram

· Interaction diagram

· Timing diagram

“Class diagram” falls under the category of structure diagram which is used to represent a static view of a system. The class diagram is not only used for visualizing, describing, and documenting different aspects of a system but also for constructing executable code of the software application. The class diagram can be mapped directly with object-oriented languages. A class diagram is an illustration of the relationships and source code dependencies among classes in UML.

A class defines methods and variables in an object, which is a specific entity in a program or the unit of code representing that entity.

Purpose of class diagram:

· Analysis and design of the static view of an application.

· Show the collaboration among the elements of the static view.

· Describe the functionalities performed by the system.

· Use an object-oriented approach for the construction of software

· Forward and reverse engineering.

Notations:

Classes are portrait as boxes instead of curly brackets. The box contains three compartments. The topmost part is where the class name is written. The middle part contains the attributes and the lower part contains the methods and operations that a class has to perform. Lines that may have arrows on one or both ends connect the boxes and shows the link or association between them.

The name of a class should be meaningful to describe the aspect of the system. Relationships should be meaningful to describe the aspect of the system. Relationships should be identified clearly. Use notes when required to describe some aspect of the diagram to be understandable by the developer.

Relationships in the class diagram:

I. Association: This is a broad term that encompasses just about any logical connection or relationship between classes. Multiplicity is an important concept in association relations.

· Multiplicity: It is an active logical association when the cardinality of a class about another is being depicted. For example, one fleet may include multiple airplanes, while one commercial airplane may contain zero to many passengers. The notation 0..*

II. Inheritance/Generalization: Refers to a type of relationship wherein one associated class is a child of another by assuming the same functionalities of the parent class. In other words, the child class is a specific type of parent class.

III. Realization: Denotes the implementation of the functionality defined in one class by another class.

IV. Aggregation: Refers to the formation of a particular class as a result of one class being aggregated or built as a collection. For example, the class “library” is made up of one or more books, among other materials. In aggregation, the contained classes are not strongly dependent on the life cycle of the container. In the same example, books will remain so even when the library is dissolved.

V. Composition: Composition relation is similar to aggregation with the only difference being its key purpose of emphasizing the dependence of the contained class to the life cycle of the container class.

Sample Class diagram:

--

--