There is a legacy class containing thousands of lines, inside which each method has also hundreds or even thousands of lines. My task is to add a new complex feature to an existing class.
The exiting class has the following features:
- fair simple responsibility, i.e. read formatted text row by row, then eventually transfer and save them into database
- class contains around 2-5 methods, one is the entry method and others are used inside the entry method. But each method is still long due to the style because:
- one method reads the column names line by line with tens of similar
if
condition - read one line of text column by column with tens of similar
if
condition - there are small validation methods used all around all methods
- methods usually have more than 5 parameters, as a result it is way difficult to add a new parameter
When adding a new feature, for instance, add a new column and the transfer of that column data has some complex logic, what I did is to create a new package
and then add many small classes into that package, only one class inside the package
is visible and thus added to the existing legacy class
Question:
Is my design more readable and maintainable than if I have added all those smaller classes as several methods into the existing class? or any other better design advise?