Method Parameters
-
Hi, I often ponder upon this. If I have a class with, lets say, 10 methods and about 6 of these methods need the same variable, is it a good idea to pass those variables as arguments to these methods? It just does not make sense to make this a member variable, in my opinion, as it has nothing to do with the state of the object, but only needed by these methods. What should I do in such a case? Should I pass them as arguments or should I declare them as member variables? Thanks before hand
-
Hi, I often ponder upon this. If I have a class with, lets say, 10 methods and about 6 of these methods need the same variable, is it a good idea to pass those variables as arguments to these methods? It just does not make sense to make this a member variable, in my opinion, as it has nothing to do with the state of the object, but only needed by these methods. What should I do in such a case? Should I pass them as arguments or should I declare them as member variables? Thanks before hand
If it's purely an argument, and is not data that should be encapsulated by the object then pass it in as an argument to the methods. You should really only use members when they encapsulate data for the object.
Deja View - the feeling that you've seen this post before.