I have a config file (text) that is read upon application startup.
If a flag, say enabled
is turned on, somewhere down the line, function handle_enabled
should be called. If it's turned off, then handle_disabled
should be called.
Obviously this can be easily achieved during run time by using either branching or polymorphism (constructing two classes. But in both cases, some overheads are imposed and the application is microsecond sensitive in terms of performance. This branching can happen hundreds of time in a second.
Is there any obvious design pattern here that allows me to achieve a form of compile-time polymorphism / branching that is configurable using a text file? I have a feeling that I may be asking for a "cheat" of sort as these two concepts seem inherently contradictory. That said, a good practice that yields better performance is appreciated too.
EDIT 1: initialization is not performance critical. Only regular execution is
EDIT 2: I've not done a profiling. Asking mainly to see if I overlook some obvious design. If not, I'll do a profiling and select a solution based on empirical data.