Skip to content

Conversation

@Amirh-Ctrl
Copy link

Hi!

I performed this refactoring as part of a small university homework assignment (HW) focusing on software design principles. The goal was to improve the code's cohesion and maintainability.

The changes address clear violations of the Single Responsibility Principle (SRP) in two utility classes:

  1. Decomposed Utils.java
    The original Utils.java was acting as a general catch-all for math, file, and data conversion logic. I split it into specialized classes:

FileUtils.java (New):

Moved addFileExtension here.

ChartMathUtil.java (New):

Moved getTickStartOffset, pow, getGeneratedDataAsList, and getGeneratedDataAsArray here.

Utils.java (Cleaned):

This class is now focused primarily on data conversion (Array/List conversion).

  1. Refactored CSVImporter.java
    This class was mixing three different responsibilities (chart assembly, file I/O, and string parsing).

FileUtils.java (Used):

Moved both getAllFiles methods here, as they are pure file system utilities.

DataConverter.java (New):

Moved the getAxisData (String to Number parsing) method here.

CSVImporter.java (Cleaned):

This class is now more focused on its main job: CSV reading and chart assembly.

I updated all the method calls in the project to point to the new utility classes and ran the Main demo in the xchart-demo module. All charts continue to work correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant