\c{
Since each widget is also a handler
(class), it suffices to install
the widget object itself as the default
handler (by invoking )
and redine the virtual functions
press and move as before.
}
\c{
For other widget classes,
the function or
the function dispatch must be redefined as well.
The difference between the two approaches is shown below.
}
\sli{\footnotesize
Declaration
button* b = new button(".b");
b->text("hello");
b->handler(f);
\c{for some} command f
Inheritance
class mybutton : public button {
public:
mybutton() { handler(this); }
int operator()() { ... }
the action
};
button* b = new mybutton(".b");
b->text("hello");
}
\c{
The command function f, installed as the handler for the
(ordinary) button, is assumed to be defined as indicated
in section action.
In comparison with the ordinary declaration of
a button with associated handler function,
inheritance is only slightly more cumbersome.
However, defining a class for each kind of widget
used may easily lead to cluttering the class name space.
What form is preferred will depend on the taste of the programmer
and the kind of application.
}