Class diagram
Class diagram
(CS-313)
Dr Naeem Aslam
Class Diagram
Introduction to Class Diagrams
• A Class Diagram is a type of UML (Unified Modeling Language)
diagram that represents the structure of a system by showing its
classes, their attributes, methods, and the relationships among them.
• Purpose:
• To model the static structure of a system.
• To serve as a blueprint for implementation.
• To facilitate communication between developers and stakeholders.
Components of a Class Diagram
A. Classes
B. Relationships
C. Visibility
Class Diagram
• Think about the things in the world around you. The things that surround you have attributes
(properties) and they behave in certain ways. We can think of these behaviors as a set of operations.
• You'll also see that things naturally fall into categories (automobiles, furniture, washing machines...).
We refer to these categories as classes.
• A class is a category or group of things that have the same attributes and the same behaviors.
• Here's an example:
• Anything in the class of washing machines has attributes such as brand name, model, serial number,
and capacity. Behaviors for things in this class include the operations "accept clothes," "accept
detergent," "turn on," and "turn off."
• Figure 1.1 shows an example of the UML notation that captures these attributes and behaviors of a
washing machine.
• A rectangle is the icon that represents the class. It's divided into three areas. The uppermost area
contains the name, the middle area holds the attributes, and the lowest area holds the operations.
Class
Attributes
Methods/Functions
Visibility in Object-Oriented Design
In object-oriented programming (OOP), visibility defines the accessibility of a class's members
(attributes and methods) to other parts of the system. It determines who can access or modify a
particular member of a class.
Types of Visibility
1 Public(+):
A Library aggregates
Books.
If the library closes
(whole is destroyed),
the books (parts) can
still exist elsewhere.
Composition
Example:
Example:
•A Printer class realizes the Printable interface.
Class Diagram of a System