According to this question and just about every style guide I've ever read, large methods are bad. However, suppose I have a method that does the following:
- Receive a JSON String from some service and store it as a Dictionary
- For various parameters in the Dictionary, creates connections to other services, such as using AWS keys to open connections to AWS services
- Downloads, Authenticates, or Manipulates data based on values in the Dictionary and new data received from step 2.
- Creates a file on the local directory and writes various values to it, dependent on step 2 and 3.
- Pushes the file from step 4 to another location
Clearly, this should not all be one large method. However, I'm not sure how to split this up into smaller methods without passing around a ton of parameters. For example, the first method is simple because I only need to tell the program one thing, and only one thing is returned. However, starting at step 3, I will either have to pass the entire Dictionary to the new method, or make the Dictionary an instance or global variable.
So, in short, here is my question. When breaking up a large method like this, what is the better alternative: should I make variables which need to be used by multiple methods instance/global variables (whichever is appropriate for this particular task), or should I pass create new methods which take many parameters?
To me, it seems like the first option is much worse, because it seems to break encapsulation: each method created in this way now has some strange dependency on a global or instance variable which is outside of its scope. However, the second method feels really messy.