button* b = new button(".b"); handler* h = new help_handler(b); b->text("Help"); b->bind(h);We assume that help_handler does something meaningful, like displaying a hypertext help file.
Alternatively, a widget may declare itself to be its own handler. In that case we derive a new class from button and define the functionality (previously defined externally in the help_handler) in the new class itself, as illustrated below:
class help_button : public button { public: help_button( char* path ) : button( path ) { this->text("help"); this->bind(this); } int operator()(); // does what help_handler did };Dependent on circumstances, either one of the approaches may be the most convenient. Allowing for delegating to an external handler helps to avoid cluttering the class name space. On the other hand, employing inheritance may result in a significant reuse of initialization code.