If static classes are bad, what should I do instead?
Stack overflow is generally of the opinion that static classes/methods are bad. I understand the benefits around maintainability, flexibility, and testing.
But then, what to do instead? If I have a bunch of helper methods inside an instantiable class, when should I create it / how many of them should I create? I could for example stick it into a static variable, either in each of the individual classes that use it, or some general class they can access. I suspect that still breaks OOP principles. But then what? Instantiate the helper class every time one of its methods get used? What if that is really often, and happens across different classes?
I'm doing games programming if that makes a difference - I doubt this specific case is going to break performance, but games tend to be much more entangled across classes/layers, and it feels really inefficient to instantiate classes every time you want to call a commonly-used, class-independent method, so I'd like some help understanding the best approach.
Posted May 17, 2023, 11:09 AM UTC