vendredi 13 janvier 2017

How to refactor a large class with many methods that have single responsibility?

Searching for design patterns and better code optimization mostly pops up articles on inheritance and relationships between classes and tools on how to create class diagrams. I would like a little insight on how to, say split, a big class. Am working on a java program with a class that has crossed 1600 lines of code and about 20 methods. What it does is query for data from a data source and generate huge text file.

Now there are lots of data modification logic(for each logic I have created small methods) that goes on to queried data like:

-check data dates of users and perform changes
-append strings
-logic to check if a record needs to be ignored

and storing filtered data in Collection and generating text file. I don't think creating separate class for each small logic is good idea. Perhaps I can create separate utility class and stuff static methods into it? I can't post code for confidentiality issues. If someone can shed a little light to get me thinking in right direction that would be great. Thanks.

Aucun commentaire:

Enregistrer un commentaire