Whenever I feel like choosing from a list of implementations I always prefer to fill a map first and then call whatever I need based on a parameter, instead of using switch or else if statements.
What is the pattern I'm looking for here? I've been told repeatedly that using maps is not the optimal solution for this, but I find writing those statements a bore.
I tagged the languages I'm currently working with, but this is not a language specific question.
switch
construct, but have the advantage of being modifiable at runtime. Any key-value data type can be used for dispatch tables, such as arrays or hash tables. VTables (a widespread mechanism to implement method dispatch on objects) essentially are a dispatch table created by the compiler. – amon Nov 11 '14 at 16:31