About methods / functions
One job per function Method classification
Basically, one function is used for each method.
Be careful of things that cannot be given a simple name. As a result, single-function ones are easier to reuse than multifunctional ones.
×
void playWholeSongAndStop(Music song)
{play}
〇
void play(Music song)
{}
void stop(Music song)
{}
It is easier to customize according to the application if it is divided into small pieces as in the above example. In the example of ×, playback is performed at double speed. Play halfway. It seems that additional functions such as are implemented.
Method classification
It is roughly classified into two types.
Code to be methodized
Basic-> Overlapping parts are made into methods ・ Methodization of conditional expressions ・ Methodization of calculation formulas -Methodization in the conditional branch block ・ Loop method -Method in loop block ・ Methodization of data conversion ・ Methodization of data confirmation -Method of array access ・ Methodization of comment part Please refer to the following source books for details of each.
How to write and divide functions, https://prettysoft.hatenablog.com/entry/20101118/1439990878
Eigen Otsuka, 2015, Coding Technology for Game Programmers, Gijutsu-Hyoronsha
This article cites the above links and books. The terms and some code have been changed to those used in Java.
Recommended Posts