If you do the right refactoring, then following the principle of Single Responsibility when describing methods, the number of arguments rarely exceeds 1, but you should not rest on this recommendation turning off the logic and breaking all common sense.
I see that the processing of data in each function affects all your data. For a start, look, is it possible to somehow process the data separately? You broke a large function into a small one, but the algorithm remains the same, maybe there is an opportunity not to affect all the data? After all, what you have done has not changed the essence of the problem ...
We treat your code:
Rethinking functions:
- A function should ideally perform only one operation. She should do it well and she should do nothing else. To make sure that the function "performs only one operation", it is necessary to check that all the commands of the function are at the same level of abstraction .
Variable refactoring:
If a function should receive more than two or three arguments, it is very likely that some of these arguments should be packaged in a separate class. Consider the following two announcements:
Circle makeCircle(double x, double y, double radius); Circle makeCircle(Point center, double radius)
Reducing the number of arguments by creating objects may seem like a scam, but it is not. If variables are transmitted together as a unit (as variables x and y in this example), then, most likely, together they form a concept that deserves its own name.
Next, you need to see if it is impossible to perform any actions in the class itself with the parameters passed in order not to perform them in a function?
Some variable refactoring rules
If the data passed to the method can be obtained by calling the method of another object, we use the replacement of the parameter by calling the method. This object can be placed in the field of its own class or passed as a parameter of the method.
Instead of transferring a group of data received from another object as parameters, the object itself can be transferred to the method using the transfer of the entire object.
If there are several unrelated data elements, sometimes they can be combined into a single parameter object, applying the replacement of parameters with an object. Suppose you passed a start, end to a function generating a report, and now just pass the DateRange object, where there are start, end parameters.
There are a lot of ways to refactor your code and it depends on the code itself and the task you are performing. It’s hard to say something when you don’t see the code, you should read the code refactoring books, for example, Clean Code. Creating, analyzing and refactoring R. Martin or the book By design patterns, to properly distribute all classes.