Robert C. Martin, The Clean Code, says the method must do one thing . Now, for example, I have two methods initialize () and play ().
initialize () should be called immediately before the call to the play () function.
The play () method will be called hundreds of times in my code. I see three approaches:
Approach-1:
Call initialize () before the game (), and this could be repeated more than a hundred times.
initialize();
play();
...
initialize();
play();
...
Approach-2:
Place the initialize () method inside play (). But this is contrary to the do-it-yourself approach.
void play() {
initialize();
...
}
Approach 3:
I have to write another method called initializeAndPlay ().
void initializeAndPlay() {
initialize();
play();
}
Is there any other better and cleaner way to do this?
source
share