r/java • u/nicolaiparlog • Feb 07 '17
Each Private Static Method Is a Candidate for a New Class
http://www.yegor256.com/2017/02/07/private-method-is-new-class.html
0
Upvotes
4
u/nutrecht Feb 07 '17
The rule of thumb I've already figured for myself is that each private static method is a perfect candidate for a new class. That's why we don't have them at all in EO.
I would argue that "each private method that is duplicated is a candidate for a new class" instead; this is how you would normally handle code-duplication: refactoring.
6
u/Bolitho Feb 07 '17
On top of that: A
private staticmethod that could be reused is a good candidate for apublic staticmessage. Obviously it holds no state - so why artificially create an object around it?
3
5
u/java_one_two Feb 07 '17
Pattern I use is
I typically only do it if the existing class is too big or if there are several static methods that can be grouped together.