UML Class Diagram With Examples
UML Class Diagram With Examples
boardmix.com/examples/class-diagram-example/
1/14
2/14
Class
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)
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
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
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().
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:
9/14
ATM: This class could have ATM_id, location, cash_available. It could have
methods like dispense_cash(), accept_deposit().
Hotel Management
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.
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.
12/14
Employee: This class could have employee_id, name, email, mobile, password and
address.
Car Modeling
13/14
14/14