The if - else ladder is fine.
In principle, it can be replaced with map<string, Function> , but it does not give anything for this particular case (added complexity without much gain, even with a large number of teams).
When I wrote this initially, I forgot to mention:
- Make your command handlers separate functions.
If you do not use t, then the if - else ladder can become quite dirty and hellip; The map solution requires separate functions and therefore may seem a little cleaner than the all-right-here staircase if - else . But these are really separate functions, which then provide clarity, while map slightly detracts (adds extra work to maintain the map and an additional level of indirection to deal with it).
On the other hand, since βreading commands from the consoleβ means interactive input, with the user in the picture, you do not want to read two or more commands from the same input line. Because it would get a hint and may seem rather perplexing to the user. Therefore, instead of reading the input word at a time using >> , use std::getline to read the complete input line at a time.
source share