> The use case is to distinguish event sources without having to retrieve their
> instances, to write general purpose event listeners. Example:
>
> public class MyButtonPressListener implements ButtonPressListener {
> public void buttonPressed(Button eventSource) {
> if (eventSource.getId().equals("copy"))
> executeCopyAction();
> else if (eventSource.getId().equals("paste"))
> executePasteAction();
> }
> }
>
> This example is clearly not good programming style, because one could as well
> write two separate button event listeners, and it is not something that Pivot
> should encourage. However, there are some situations where this might be
> handy.
I agree that this is not good programming style, but for a different reason. In
this example, you have simply exchanged typed member variables for string IDs -
i.e. you have lost information and compilation benefits.
You still need to define an identifier, whether it is a "copy" ID or a
"copyButton" member variable, to determine the source of the event. IMO, the
member variable is preferable. The overhead of retrieving and maintaining the
instance is negligible and the approach is much more flexible.