What are the pros and cons of using Observer versus just registering callbacks like:
worker.setOnJobIsDone(func);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you use function pointers, the object is completely unaware of its users; it just calls a function which allows for more flexibility (the users don’t need to inherit anything, you can wire users of this object as you like).
Observer pattern requires you to define an interface. This is less flexible but more explicit.
I prefer the observer pattern strongly for the sake of readability; it is much easier to track workflow if you’ve never seen the code before. Also C++ syntax for passing member functions is kind of hard on the eyes.