lundi 14 août 2017

Reflection + function pointers vs Observer pattern

I have got a program which gets commands via network and allocates these to a specific function. And now I want to implement a plugin feature where I can add a .dll file in a folder. The next step is to invoke the methods in the dll based on the command.

I have two ideas how to solve this problem but I do not know which of these is better/more performant:

  1. Initializing all methods + commands from the dll with reflection and store them in a std::map<std::string, void(*func)(args...)>. When the program recieves a command it looks up the associated function in the map and invokes it.
  2. Load the dll into runtime and create an interface which hands over the std::string with the arguments to all dll's which have implemented it. The method in the dll uses if statements to check the command can be processed in there. (Observer pattern)

If there are better options which I have not mentioned let me know.





Aucun commentaire:

Enregistrer un commentaire