OSSpk / Library-Management-System-JAVA

📚 A sophisticated Library Management System designed in Java while following the concepts of decoupled layers (entities) and minimal code in interface (GUI).
https://github.com/harismuneer
MIT License
353 stars 231 forks source link

Requirement of Refactoring in the code #1 #9

Open guryashdhall opened 2 years ago

guryashdhall commented 2 years ago

Refactoring Required

1) Extract Method

Class to be updated: Borrower.java

Initially the method updateBorrowerInfo() had three functionalities of updating the name, address and phone number. These functionalities are separated by creating individual methods for each functionality updateBorrowerName() , updateBorrowerAddress() and updateBorrowerPhoneNumber().

This not only makes the code more readable and understandable but can also be used in extending the functionality of the Library management system by providing only the option of changing the name to admin and giving just the access of changing address and phone numbers to individual borrowers.

image image

2) RENAME METHOD/VARIABLE

Class: Borrower.java

image Class: Person.java image

3) Move Method

Add Librarian function should be there in Librarian class instead of Library as it is better suited to be the component of that class.

image

4) Extract Class

Class: Book.java Hold Requests operations are performed inside the book class. And this violated the principle of single responsibility, so the responsibility is split by creating a new class HoldRequestOperations.

image

5)Changing Bidirectional Association to Unidirectional

Object or instance variable of HoldRequest is used in various classes. Because of this, there is a bidirectional relationship between Hold Request and Book class. Using HoldRequestOperations class changes the bidirectional relationship to unidirectional. In the future, for any additional features/modifications, users will not need to look up and make changes to several classes.

Thanks for giving me the opportunity to refactor your code! Please let me know your suggestion/feedback for the same