Java – Should I add parameters to instance methods that use those instance fields as parameters

design-patternsjava

I have an instance method that uses instance fields in its work. I can leave the method without that parameters as they're available to me, or I can add them to the parameter list, thus making my method more "generic" and not reliable on the class. On the other hand, additional parameters will be in parameters list. Which approach is preferable and why?

Edit: at the moment I don't know if my method will be public or private.

Edit2: clarification: both method and fields are instance level.

Best Answer

IMO, "making my method more "generic" and not reliable on the class" is not a good goal, since it promotes classes with low cohesion.

If your method is generic enough to serve for other classes, too, then take it out of the class and move it to a "function library" class. (But beware of the functional decomposition antipattern).