Class Diagram
In software engineering, a class diagram in the Unified Modeling Language (UML) is a
type of static structure diagram that describes the structure of a system by showing
the system's classes, their attributes, operations (or methods), and the relationships
among objects.
A class diagram is used to visualize, describe, and document different aspects of the
system
A UML class diagram is made up of:
A set of classes and
A set of relationships between classes
What is a Class?
A description of a group of objects all with similar roles in the system, which consists
of:
Structural features (attributes) define what objects of the class "know"
Represent the state of an object of the class
Are descriptions of the structural or static features of a class
Behavioral features (operations) define what objects of the class "can do"
Define the way in which objects may interact
Operations are descriptions of behavioral or dynamic features of a class
Class Notation
A class notation consists of three parts:
1. Class Name
The name of the class appears in the first partition.
Some of the following rules that should be taken into account while representing
a class are given below:
2. Capitalize the initial letter of the class name.
3. Place the class name in the center of the upper section.
4. A class name must be written in bold format.
Class Attributes
Attributes are shown in the second partition.
The attribute type is shown after the colon.
Attributes map onto member variables (data members) in code.
The attributes are written along with its visibility factors, which are public (+),
private (-), protected (#), and package (~).
5. Class Operations (Methods)
Operations are shown in the third partition. They are services the class
provides.
Relationships
Dependency: A dependency is a semantic relationship between two or more classes where a
change in one class cause changes in another class.
o Student_Name is dependent on the Student_Id.
o Generalization: A generalization is a relationship between a parent class
(superclass) and a child class (subclass). In this, the child class is inherited from
the parent class.
For example, The Current Account, Saving Account, and Credit Account are the
generalized form of Bank Account.
o Association: It describes a static or physical connection between two or more
objects. It depicts how many objects are there in the relationship.
For example, a department is associated with the college.
Multiplicity: It defines a specific range of allowable instances of attributes. In case if a
range is not specified, one is considered as a default multiplicity.
For example, multiple patients are admitted to one hospital.
Aggregation: An aggregation is a subset of association, which represents has a
relationship. It is more specific then association. It defines a part-whole or part-of
relationship. In this kind of relationship, the child class can exist independently of its
parent class.
The company encompasses a number of employees, and even if one employee resigns,
the company still exists.
Composition: The composition is a subset of aggregation. It portrays the
dependency between the parent and its child, which means if one part is deleted,
then the other part also gets discarded. It represents a whole-part relationship.
A contact book consists of multiple contacts, and if you delete the contact book, all
the contacts will be lost.
Class Diagram Online ordering System
Class Diagram College management System
Class Diagram Airline Reservation System