| Author |
Calling an object's get functions multiple times in same code segement? Bad Practice?
|
David Dickinson
Ranch Hand
Joined: Nov 11, 2004
Posts: 66
|
|
Hi, I'm tidying up my code and im considering creating a few extra fields to my code to save me repeatedly calling the same get function when the same value will be returned. I have a method which sums up values but I also want to print these values in the same method like so.. Would it be better to store the value in a variable at the start of the method and save the repeated getValue() calls? Thanks
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
If getValue() is a simple getter, then no, not really; any time that you'd save would be infinitessimal. Let me give you some advice, though: having each method do One Thing and One Thing Only is a worthy goal to strive for. Methods that two something, and, oh, by the way, do this other thing too, lead to muddled designs and difficult code.
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: Calling an object's get functions multiple times in same code segement? Bad Practice?
|
|
|