Ktoś mnie kiedyś nastraszył, że metody statyczne to zło i teraz mnie to prześladuje. Opinie w sieci jeżeli chodzi o same metody statyczne są podzielone:
One rule-of-thumb: ask yourself "does it make sense to call this method, even if no Obj has been constructed yet?" If so, it should definitely be static.
The basic issue with static methods is they are procedural code. I have no idea how to unit-test procedural code. Unit-testing assumes that I can instantiate a piece of my application in isolation. During the instantiation I wire the dependencies with mocks/friendlies which replace the real dependencies. With procedural programing there is nothing to "wire" since there are no objects, the code and data are separate
Właśnie siedzę nad wzorcami projektowymi i po prostu pasuje mi tutaj metoda statyczna.. mimo to na wszystkich stronach, gdzie ten pattern jest tlumaczony jest to zwykła klasa, którą instancjujemy.
Argument z testowaniem trochę do mnie nie przemawia, ale nie mam dużego doświadczenia w TDD, w zasadzie ucze się wszystkie na raz. Jeżeli np. mam strategie sortowania, to mogę przecież zrobić assercję na [1, 2, 3, 4, 5] i sprawdzić, czy po sortowaniu metoda zwraca mi tablicę posortowaną czy nie.