What Is a Class Diagram in Simple Terms
A UML is also known as a Unified Modeling Language diagram. It is 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
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 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
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
- /: Derived (calculated or derived value)
- ~: 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().
- 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.
- 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().
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.
- 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, 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(), and make_payment().
- Product: Its attributes might be product, name, category, or 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.
- Payment: Its attributes might be payment_id, order_id, amount, and 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, and account_number. It could have operations like insert_card(), enter_pin().
- Account: Its attributes might be account_number, balance, or account_type. It can have operations like withdraw_cash(), check_balance().
- ATM: This class could have ATM_id, location, and cash_available. It could have methods like dispense_cash(), and 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.
- 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.
- 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.
- 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(), and move_backward().
- Engine: Its attributes might be capacity, and number of cylinders.
- Gear Box: This class could have gear_ratio, and current gear.
How to Create a Class Diagram
Creating a class diagram using Boardmix is an intuitive and user-friendly process. Follow these steps:
- Visit the Boardmix website and log in to your account.
- Navigate to the Templates. From there select UML Class Diagram.
- Choose a template that fits your needs or start from scratch.
- Add classes by clicking on the Class button.
- Now fill in the class name, attributes, and methods.
- You need to connect the classes using relationship lines and define the type and multiplicity of the relationship.
- Customize the look of your diagram with Boardmix’s design tools.
- Save, export, or share your diagram directly from the Boardmix platform.
Final Words
As for software engineers and system architects, mastering the implementation and understanding of UML class diagrams is essential. These diagrams provide a systematic visualization of system components and their interrelationships. Moreover, you get aid in the design process and enhanced communication among stakeholders.
Now making UML class diagrams has become a more accessible task by using Boardmix's intuitive platform and ready-made templates. Be it a simple ATM system or a complex hospital management system, class diagrams serve as the fundamental blueprint, offering a clear overview of your system architecture. Leveraging such tools can make system design more convenient and efficient.