LAB ASSIGNMENT#2
OOP
(Object Oriented Programming)
Student Name: Raja Aneeq Abid
Registration No: SP25-BSE-042
Department: Software Engineering
Submission Date: 13th
OCTOBER 2024
COMSATS University Islamabad
Library Management System - OOP Report
Task 1: Class Diagram (2 Marks)
Diagram is on the pdf attached.
Task 2: Forward Engineering (1 Mark)
The class diagram has been converted into java code in the attached file
[Link].
Concepts such as encapsulation, inheritence, composition, aggregation and
exception handling etc have been implemented according to OOP principles.
Task 3: Reverse Engineering (1 Mark)
The class diagram of the final code is almost the same as the origional
concept diagram.
Relationships like composition, aggregation, and inheritance were accurately
maintained.
Minor changes may exist in method naming or additional utility methods,
but the overall structure remains virtually the same.
Task 4: Decomposition into Objects (1 Mark)
Objects:
1. Library: manages books and members. Borrowing and returning
books.
2. Book: represents each book and tracks copies.
3. Member: parent class for all member types.
4. Student, Teacher, Librarian: inherited from member.
5. Address: represents member’s address.
Decomposition improves reusability and maintainability by dividing the
system into smaller, manageable components.
Each class handles its own responsibility, making updates easier and
minimizing code duplication.
Task 5: Composition and Aggregation (1 Mark)
Composition:
Implemented between Library and Book.
Library is composed of Book.
Book can not exist without Library so it is a strong relation.
Example: A Library has Books.
Aggregation:
Implemented between Member and Address.
Address does exist even if the member is gone.
First the adress is created and then assigned to the member so it’s a
weak relation.
Example: A Member has an Address.
Composition ensures that if the Library object is destroyed, its Books are
also destroyed,
whereas Aggregation allows the Address to exist independently of the
Member.
Task 6: Inheritance and the Super Keyword (1 Mark)
Inheritance:
Implemented between Member (parent) and Student, Teacher, Librarian
(subclasses).
Example:
class Student extends Member {
public Student(String id, String name, String program, int sem) {
super(id, name);
The super keyword is used to call the constructor of the parent class and
reuse its properties and methods.
The super class is also used to call the methods of the parent class like in the
display function in my code.
public void display(){
[Link]();
[Link]("Program: "+[Link]);
[Link]("Semester: "+[Link]);
This promotes code reuse and simplifies structure.
Task 7: Constructor Chaining (1 Mark)
Constructor chaining is demonstrated in the Book class:
public Book() {
this(A1234, “Java”, “Mohsin”, 1);
}
This technique avoids duplication of initialization code and ensures
consistent object setup.
Task 8: Encapsulation and the Final Modifier (1 Mark)
Encapsulation:
Implemented using private attributes and getter methods in classes like
Book.
Example:
private final String BookId;
private String title;
public String getBookId() { return BookId; }
Final Modifier:
Used for immutable fields and classes.
Example:
final class Address { ... }
private final String BookId;
Protected Access Specifier:
Used in Member class for controlled subclass access.
Example: protected String memberId;
Task 9: Exception Handling (1 Mark)
Exception handling is used when borrowing or returning books that are
unavailable or do not exist.
Example:
try {
[Link]("S001", "B5678");
} catch (Exception e) {
[Link]("Expected error: " + [Link]());
}
This prevents program crashes and ensures smooth error management.