As per this anwer methods that do I/O are not 'pure functions' and shouldn't be static. On the other hand this highly upvoted answer makes me think if I don't need any object to call a method it should be static.
I have a class that simply helps in fetching data over a URL. The class has exactly 1 method that does some url preprocessing and calls apache's IOUtils underneath. Should it or should it not be static. The class doesn't have any state and the only state it can modify is outside itself.
- I know static methods are hard to test but that feels more an artifact of not having proper dependency injected rather than using a static method. [1]
- If static methods that do I/O are scorned upon, why does apache's IOUtils have static methods that fetch bytes from a URL etc. (example : https://commons.apache.org/proper/commons-io/javadocs/api-2.5/org/apache/commons/io/IOUtils.html#toByteArray(java.net.URL))
[1] Why is injecting classes with static methods hard. Is this by design? I mean, I don't want to be forced to pass in a java.lang.Class and use reflection to call the static method -- that feels scary and ugly at the same time. All I want is the ability to pass in a reference to a class (not an object) that has some functionality. Even testing framework PowerMock that supports mocking static methods does it by hacking bytecode and I want to avoid that if possible.
What is the general guidance around this?