c++ - Reflection + function pointers vs Observer pattern -


i have got program gets commands via network , allocates these specific function. , want implement plugin feature can add .dll file in folder. next step invoke methods in dll based on command.

i have 2 ideas how solve problem not know of these better/more performant:

  1. initializing methods + commands dll reflection , store them in std::map<std::string, void(*func)(args...)>. when program receives command looks associated function in map , invokes it.

  2. load dll runtime , create interface hands on std::string arguments dll's have implemented it. method in dll uses if statements check command can processed in there. (observer pattern)

if there better options have not mentioned let me know.

although using incorrect terminology describe want, option 2 "cleaner"

forcing singular interface implemented plug-in dlls best-practice way of establishing sort of dependency injection you're seeking, in opinion.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -