In GWT, a listener object A may attach itself to many other widgets. These widgets will call A's onChange (or similar) method, and pass themselves as onChange's only parameter. Inside onChange, A must then decide which widget called it. At this point a programmer unfamiliar with the code faces a problem: there is no easy way for her to tell which of the widget's many methods and properties are intended to be used by A. The solution given here is to create an interface, named [widget's name]Event, that has only methods to be used inside of onChange. This makes for clean and understandable code.
public void onChange(Widget sender)The problem is the "possibly using data from X". If A and X were written by two different programmers -- perhaps widget X is a third-party widget --, how on earth is the programmer for A supposed to know what to do with X (apart from reading the documentation, if it exists)? Only some of X's methods will be intended to be used by a listener, but which ones? X may have many, many methods which have nothing, absolutely nothing, to do with what A wants to do when X changes.
{
if(sender == X)
{
// do stuff, possibly using data from X
}
if(sender == Y)
{
// do stuff, possibly using data from Y
}
// etc
}
public void onChange(Widget sender)
{
if(sender == X)
{
XEvent event = (XEvent) sender:
// do stuff with event: ignore X!
}
// etc
}
