Pete Barrett wrote:
> On Sun, 28 Aug 2005 21:21:59 -0400, ""
> <> wrote:
>
>>Exactly what are the benefits of extending EventObject and EventListener
>>for event delivery... Why not just use simple straight forward
>>interfaces. Something like:
> It's extensibility, I think. If you change that
> applesAdded(FruitBasketEvent evt) to fruitAdded(FruitBasketEvent evt),
> then the salient difference becomes more obvious - information about
> the fruit being put in the basket is localised in the event, which
> means that it's localised in the class that fires the event. The class
> which consumes the FruitBasketEvent can examine the event and discard
> any fruit it's not interested in.
There are a number of other reasons.
It allows you to to write code with greater type-safety. You can write
code to deal with EventListener and EventObject, giving an indication of
what does what. For instance, javax.swing.EventListenerList.getListeners
will return an array, but the component type of that array must extend
EventListener. This doesn't necessarily give you complete type safety,
but does provide an indication of what is going on.
It also helps with bean and tool support. You have marked intention in
an unambiguous way.
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/