Callbacks in C++

separate client and server interface specifications


Obvious implementations of Parameterize Method Name in C++ require the signature and return type of the client's member function to exactly match the calling signature of the callback. This requirement is more strict than what happens with direct function and member function calls in C++.




Apply the template form of Abstract Client to the callback template. In doing so, you will add a template parameter for the type of the member function pointer.

forces resolved:

design rationale:

The point of the template version of Abstract Client is that you give your class a template argument for a type, and the allow the code that uses that type to specify what interface that type must have. By applying this pattern, there is no need to explicitly declare a pointer to a member function. Any type is actually allowed as long as the type has a copy constructor and it is legal to use an object of that type with the member function pointer invocation syntax.

The reason for identifying this as a separate pattern is that it is not obvious that Abstract Client can be applied in this situation. Abstract Client appears to have nothing to do with pointers to member functions. Until you have been shown that the syntax for invoking a method through a function pointer is just an interface specification that pointers to member functions happen to fill. Due to the nature of this syntax, and the ability to arbitrarily overload the behavior of the operator that is used, there actually is a wide variety of objects that can fill the role of the pointer to a member function.

This pattern is usually used in conjunction with the Automatically Detect Types pattern.

[View/Add Comments]

Callbacks in C++
Copyright © 1996-2000 Paul Jakubik
Created: 26 July 1996. Last update: 26 November 2000.