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:
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.load dll runtime , create interface hands on
std::string
arguments dll's have implemented it. method in dll usesif
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
Post a Comment