When is it good form to push a local variable to a function/method as a parameter, rather than using a class variable in place of the function/method variable.
For i
I look at it in terms of dependency, i.e. who is dependent on the variable (in your case var
), is it a method or a class?
For e.g. JavaBeans have class variables that are dependent by the class, so if the class needs these variables then DoSomething()
is best.
Alternatively, if you class doesn't care about var
and doesn't need it anywhere else, and only DoSomething()
requires var
, then DoSomething(int var)
is essential.