I'm doing some research in how to implement a event-handling scheme in C++ that can be easyest as its to implements an adpter to a class in java. The problem is that with the approach shown below, I will need to have all adapters already implemented with its function overriding in the devived class (because the linker needs it). On the other side, using a delegate strategy where I can use the adapter just in the derived class should imply in less performance considering the way it need to be implemented.
wich one, or what on else should be the best approach to it?
class KeyboardAdapter
{
public:
virtual void onKeyDown(int key) = 0;
}
class Controller : public KeyApadter
{
private:
void onKeyDown(int key);
}
void Controller::onKeyDown(int key) {}
class UserController : public Controller {
private:
void onKeyDown(int key);
}
void UserController::onKeyDown(int key) {
// do stuff
}
int main() {
UserController * uc = new UserController();
Controller * c = uc;
c->_onKeyDown(27);
}