Wikidata / Wikidata-Toolkit

Java library to interact with Wikibase
https://www.mediawiki.org/wiki/Wikidata_Toolkit
Apache License 2.0
372 stars 100 forks source link

Codebase Refactoring for Improved Readability and Maintainability #861

Closed risvarrt closed 3 months ago

risvarrt commented 5 months ago

This pull request introduces a series of six refactoring changes aimed at enhancing the readability, maintainability, and overall design of the codebase. Each refactoring is summarized below:

Introduce Explaining Variables

Refactored the equalTimeValue method within the Equality class by adding two explaining variables: equalTimeStamp and equalTolerance.

Extract Method

Simplified the getJsonDatatypeFromDatatypeIri method in the DataTypeIdImpl class by extracting logic for the default case to a new method, enhancing readability.

Decompose Conditional - WbEditingAction

Improved the performAPIAction method within the WbEditingAction class by decomposing conditional logic into smaller methods (validateIfnewEntity, validateEditEntityDataUsingId, validateEditEntityData), focusing on core logic.

Extract Class - DataTypeJsonUtils

Introduced the DataTypeJsonUtils class to separate JSON conversion logic from execution logic, adhering to the Single Responsibility Principle.

Move Method - getReferenceUri

Improved design by moving getReferenceUri logic from Vocabulary to ReferenceRdfConverters, aligning responsibilities with the classes most directly involved.

Pull up Variable - constructTermMap and toTerm

Centralized the constructTermMap and toTerm methods by pulling them up into the StatementDocumentImpl class. This change eliminates duplication and simplifies constructTermMap across various inherited classes.

Each refactoring change preserves the existing functionality and interface contracts, ensuring backward compatibility and uninterrupted operation. The focus has been on internal improvements that enhance our code's structure without altering its behavior from an external viewpoint.

Your feedback and suggestions on these refactorings are welcome.

risvarrt commented 5 months ago

Yes, It is a part of my assignment. Also, I wanted to apply my learnings on refactoring and code smells on this repository Let me know if any other changes are needed here.

wetneb commented 5 months ago

Ok. Would you be able to share the detailed instructions you have been given for this assignment?