0% found this document useful (0 votes)
12 views14 pages

UML Class Diagram With Examples

A UML Class Diagram is a static diagram that outlines the structure of a system, detailing classes, objects, attributes, and their relationships. Key notations include classes represented as rectangles, associations as solid lines, and dependencies as dashed lines. The document provides examples of class diagrams for various systems such as online shopping, banking, and hospital management, illustrating the attributes and operations of different classes.

Uploaded by

Muhammad Auwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views14 pages

UML Class Diagram With Examples

A UML Class Diagram is a static diagram that outlines the structure of a system, detailing classes, objects, attributes, and their relationships. Key notations include classes represented as rectangles, associations as solid lines, and dependencies as dashed lines. The document provides examples of class diagrams for various systems such as online shopping, banking, and hospital management, illustrating the attributes and operations of different classes.

Uploaded by

Muhammad Auwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Master UML Class Diagram with Examples

boardmix.com/examples/class-diagram-example/

What Is a Class Diagram in Simple Terms


A UML is also known as a Unified Modeling Language diagram. It is basically a type of
static diagram that shows and identifies the whole structure of a system. This diagram
gives you an overview of how a code and application should be structured and designed
before implementing a code. Mainly a class diagram holds the classes, objects, attributes,
and relationships as well as dependencies between different classes.

Notations & Symbols of a Class Diagram

1/14
2/14
Class

Class is represented as a rectangle with three sections. These sections are:

Top section:Contains the class name.


Middle section:Lists the class attributes (variables or properties).
Bottom section:Lists the class operations (methods or functions).

Association
The association is represented as a relationship between two classes. It is depicted by a
solid line connecting the classes. The line might have an arrowhead to indicate the
direction of the association. Multiplicity can be shown near the end of the line to indicate
the number of instances related.

Aggregation
Aggregation basically represents a "whole-part" relationship between two classes. It is
depicted by a diamond shape on the side of the "whole" class, connected to the "part"
class with a solid line. The diamond shape points towards the "whole" class.

Composition

Next on, you will notice composition. It is similar to Aggregation but with a stronger
relationship. It indicates that the "whole" class owns the "part" class, and their lifecycles
are tightly linked. It is depicted by a diamond shape on the side of the "whole" class,
connected to the "part" class with a solid line. The diamond shape is filled with black.

Inheritance/Generalization
Inheritance/ Generalization is an "is-a" relationship between two classes. It is depicted by
a solid line with an arrowhead pointing from the subclass to the superclass.

Interface

The interface is represented as a circle having the name of the interface. It shows the
contract that a class must implement. The interface is connected to the implementing
class with a dashed line.

Dependency

3/14
Dependency is known as a weaker relationship between two classes, where one class
depends on the other but not in a "part-of" relationship. It is depicted by a dashed line
with an arrowhead pointing from the dependent class to the class it depends on.

Multiplicity

Multiplicity represents the number of instances. These instances are associated one class
with another class. Multiplicity is shown as a range (e.g., 0..1, 1..*, etc.). You will notice it
near the end of the association line.

Modifiers
Symbols used to indicate access modifiers for class members:

+: Public
-: Private
#: Protected
~: Package (default or package-level access)

10 Class Diagram Examples


The following are UML class diagram examples:

Online Car-hailing System


In an online car-hailing system class diagram, we could have some o the following
classes:

User:Attributes may include user_id, username, password, and contact. Also,


operations may include log_in(), log_out(), request_ride().
Driver: This class could have attributes like driver_id, name, contact, and status
(available or unavailable). It will also have an operation that may include
accept_ride().
Ride: Attributes may encompass ride_id, pickup_location, dropoff_location, and
fare. It can have operations like calculate_fare().

4/14
Vehicle: Attributes could be vehicle_id, driver_id, model, and status ( whether it is
available or booked).

Banking System
Here, some of the following classes could be used:

Customer:This class could have attributes like customer_id, name, address, and
contact_number. Methods could include create_account(), request_loan().
Account: Attributes could include account_number, customer_id, balance,
account_type. It could have operations like debit(), credit(), check_balance().
Loan: The loan class could have loan_id, customer_id, amount, interest_rate as
attributes, and approve_loan(), calculate_interest() as methods.

5/14
Transaction:Its attributes might be transaction_id, account_number,
transaction_type, amount, date.

Hospital Management

For such a system, we could use some of the following classes:

Patient:This class could have attributes like patient_id, name, DOB, address, and
medical_history. It could have operations like admission (), and discharge().
Doctor: This class could have attributes like doctor_id, name, specialization, and
availability. It can have operations like assign_to_patient(), perform_surgery().
Nurse:Nurse class could have attributes like nurse_id, name, shift, and
ward_assigned. It could have methods like give_medicine(), check_vitals().
Appointment:Its attributes could be appointment_id, patient_id, doctor_id, date,
time. It can have operations like schedule_appointment(), cancel_appointment().

6/14
Library Management

This could include some of the following classes:

Librarian: Attributes could include librarian_id, name, contact_number. It could


have methods like issue_book(), return_book().
Member: This class might have member_id, name, membership_date, fine_due as
attributes and borrow_book(), return_book() as operations.

7/14
Book:Its attributes could be book_id, title, author, and status (available or
borrowed). It could have operations like get_details(), and check_availability().

Online Shopping System

Here, the some of the following classes could be used:

Customer:This class could have attributes like customer_id, name, address, and
contact_number. It could have operations like place_order(), make_payment().
Product: Its attributes might be product_id, name, category, price. It can have
operations like add_to_cart(), and purchase().
Order: It could have order_id, customer_id, product_id, total_price as attributes and
process_order(), deliver_order() as methods.

8/14
Payment:Its attributes might be payment_id, order_id, amount, payment_method. It
could have operations like make_payment(), and refund().

ATM System
For this system, we could use some of the following classes:

Customer: This class could have attributes like customer_id, name,


account_number. It could have operations like insert_card(), enter_pin().
Account: Its attributes might be account_number, balance, account_type. It can
have operations like withdraw_cash(), check_balance().

9/14
ATM: This class could have ATM_id, location, cash_available. It could have
methods like dispense_cash(), accept_deposit().

Hotel Management

This could include some of the following classes:

Guest: This class could have attributes like guest_id, name, contact_number. It
could have operations like check_in(), check_out().
Room: Its attributes might be room_number, type (single, double, suite), status
(available, occupied), price_per_night.

10/14
Receptionist:This class could have receptionist_id, receptionist_name,
receptionist.

Start a Free Class Diagram

Registration System
For the registration system, we could use some of the following classes:

User: This class could have attributes like user_id, username, password. It could
have operations like register(), login(), logout().
Admin: Its attributes might be admin_id, login_id and admin_name.

11/14
Registration Information:This class could have attributes like registration_id,
registration_name, registration_age and registration_gender.

Airline Reservation System


Here, some of the following classes could be used:

Passenger:This class could have attributes like passenger_id, name,


contact_number. It could have operations like book_ticket(), cancel_ticket().
Airline:Its attributes might be airline_id, description, type, schedule_date.

12/14
Employee: This class could have employee_id, name, email, mobile, password and
address.

Car Modeling

For this, we could use some of the following classes:

Car:This class could have attributes like registration_id, year, license_number.


It could have operations like move_forward(), move_backward().
Engine:Its attributes might be engine_capacity, number of cylinders.
Gear Box:This class could have gear_ratio, current gear.

13/14
14/14

You might also like