Skip to content

Refactor Description

Hamish Patel edited this page Oct 8, 2024 · 7 revisions

For this code refactor, the main concerns were usability, maintainability and readability of code. The goal of this refactor was to improve the current codebase without changing the functionality of the code. Discussed below are various tasks done to refactor the code.

Component Extraction

Previously, there were areas where a lot of the frontend logic was repeated directly into its associated classes. The main concern of this was repeating code in multiple classes, making them unnecessarily long and difficult to read.

Changes Made

An example of this is the RecipeCard logic. Originally, it was troublesome to add another recipe card in our project as we would have to write the full frontend logic again. Before:

FeatureToday.jsx image

After:

RecipeCard.jsx image

FeatureToday.jsx image

How Maintainability Has Been Improved and Examples

By extracting the RecipeCard logic into it's own component, it becomes reusable and more maintainable. For example, if we have to add new cards or features relating to user interaction, this separate RecipeCard.jsx class can be reused easily as a single, isolated component. This would also reduce error and debugging time as we would only need to focus on one component class rather than the same logic copied many times in many places.

Improved Readability

Formerly, many methods and sections in the project were time consuming to understand due to the lack of JavaDocs in the codebase. Without proper documentation, a lot of time would be spent in understanding the code as we were left to derive the explanations ourselves.

Changes Made

We have added JavaDocs in the codebase for better readability and documentation. An example is given below

Before:

No Comments image

After:

Adding Comments image

How Maintainability Has Been Improved and Examples

By adding meaningful comments in critical areas, the refactor improved the maintainability of the code by providing clear documentation so future development is easier and faster. For example, if we want to reference certain methods for the logic of the code it is quite easy to pinpoint what method we want to call due to the documentation providing clear and concise reasoning and explanation of the component which also, in turn, supports the longevity of the code.

Clone this wiki locally