Tag Info

New answers tagged

2

I find it extremely rare that one would need to mock the methods of a utility class. A very important OOP principle is that state is represented by objects, and that dictates that static methods - which don't operate on an object - should be stateless. You don't need to mock functionality. If you are testing code that depends on your factorial ...


5

I'm all for fighting fire with fire, but turning bad code (lots of static methods) into other bad code (lots of singletons) doesn't sound like such a good idea to spend time on really. From what you have written, this is all in a legacy code context, but you do have change access to the source where those static methods reside (maybe all, but the rest is ...


0

First of all, have you tried to ask your co-worker what would be the benefits of his approach ? From my point of view, the only advantage of having a singleton (and basically object methods) is to ensure that later on, you will be able to extend those functions (or to mock them), and change the behavior of code that relies on it. This is especially useful if ...



Top 50 recent answers are included