When it's a good form to move a local variable to a function / method as a parameter, instead of using a class variable instead of a function / method variable.
For example, I may have a function:
int DoSomething(int var) { if(var == -1) return 0; }
or I can have a class variable "_var" and use it in the same function, for example:
int DoSomething() { if(_var == -1) return 0; }
I mean, if I have a class variable that will be used in some function / method called DoSomething in my example above, I have to send the DoSomething function / method to the class variable as a parameter, so the function is easier to read and test.
When is it in good shape? I know this is a loaded question, but I am trying to make an argument for my argument with a collaborator, and they state that I will add more code to the function / method signatures, instead of supporting less function / method signatures.
In my opinion, I make the code cleaner and easier to maintain by clicking on the class variables on the corresponding functions / methods, rather than making them rely on / aware of the existence of the class variable.
Please inform.
java c ++ function object design
Rick
source share