Concepts (4 Part Series)
In accordance with the SRP principal we can train ourselves to recognize when to split out responsibilities while coding.
Take this example:
Do you see any concern with respect to SRP? Why yes, what is the call to UpdateArray doing? Is updating an array related to setting the state of an object? The answer is no.
Updating an array has nothing to do with stetting an object state. If we leave that code in, then it's most likely not going to be re-usable. A subsequent specification stated, repeat the HTTP get until a certain state is seen, then stop. In this case, by adding the repeated responses to the array, the output looked like this:
Each additional try was adding to the Array where, what needed to be done was each new response needed to replace the content. There's duplicate records in the array!
Simply make a local array and return it. This localizes the array and allows the consumer to deal with it and does not mix concerns.