java - private static throughout code -
i on new project, , legacy java code filled classes using mix of private static methods, , public static methods.
it's hard follow.
for example:
public car { private static checkgas(){ .. } public static startcar(){ checkgas(); } }
is there design pattern never heard of make applicable?
i've used public static methods on "helper" classes not need util.caculate(..)
, , in above "car" example wouldn't have use private static or public static methods... private , public methods.
you want limit access tightly possible, if have utility class public static methods , static helper methods call, helper methods should private.
this not fundamentally different writing non-static private helper methods support non-static public methods.
i wouldn't call design pattern, general practice.
don't make things public unless have to. once method public, can't modify signature without breaking uses it.
edit
regarding best place put static methods, i'd rather put them on class they're designed help, rather aggregate random static methods in "util" class.
a example of integer
class, can instantiated represent numerical value, has many static helper methods compare
, max
, parseint
, etc.
utility classes should things generic, such math
class.