📎 Webclip
Each Private Static Method Is a Candidate for a New Class
The article argues that when a private static method appears to factor out logic, it is often a sign that the logic should live in a separate class. The key difference is that a class can be reused and tested, while a private static method cannot.
Reading notes#
- A private static method may make code shorter, but it stays confined to one class.
- If the same logic is needed elsewhere, the method has to be copied and pasted.
- A separate class makes the shared behavior reusable.
- The example refactors URL encoding into an
Encodedclass. - That class can be used in multiple places and covered by a unit test.
- The author treats each private static method as a candidate for a new class.
- The note also says this reasoning may apply to all private methods, not only static ones.
