Search code examples
c++event-handlingvirtualsignals-slots

Signal Handlers vs Virtual Functions & Inheritance (Event Handling)


I have a basic Window class that I need to have events such as MouseDown, MouseUp, WindowResized etc. I have two possible routes: Signal handlers (e.g. Boost.Signal) or virtual functions where the user of the class creates a class derived from Window and overrides the OnMouseUp, OnMouseDown and OnWindowResized functions. What are the advantages and disadvantages of each or is it a matter of style?

I am writing this in C++ but I guess the concept is more important.

Thanks in advance, ell.


Solution

  • This is a study related to the performance of various approaches (plain c, virtual, boost::signal, etc.). Study

    According to this there are some serious problems with the boost.signal. To be frank with you I haven't used much that library though I thought it is a very interesting question as I was toying with the same idea. As it stands I would go with the virtual implementation.

    Regards. :)