Insert Witty Irony Here

vince kraemer's Weblog


20070727 Friday July 27, 2007

Java API design antipattern and tip

The Antipattern: Don't Create an Event Object for Your Listener Interface's Methods

I discovered this while trying to implement against a Listener interface that just sent in the "interesting" parts of the event... A String or two.

I needed to find out the source of the event (which is a pretty standard member of an Event interface), so that I could react to the event. This is easy to resolve by creating the listener with an additional member for the "expected" source. Or it is easy to resolve until you try to garbage collect these listeners that know their source...

An Event/Listener pair helps your API mature gracefully. Additional members/accessors can get added to the Event side of the interface without requiring changes in code that implements the Listener, unless the listener wants to USE that new member/accessor.

In the interest of transparency and honesty; I have to admit that I helped review and approve the Listener interface that lead to this entry. It just goes to show the value of having to write REAL code against an interface before you say, "Oh. That looks fine."
(2007-07-27 13:48:26.0) Permalink

Calendar

« July 2007 »
SunMonTueWedThuFriSat
1
3
4
5
6
7
8
9
10
11
13
14
15
16
17
18
19
20
21
22
23
25
28
31
    
       
Today

RSS Feeds

XML
All
/5 in 5
/Compile Time
/Ease of Evolution
/General
/GlassFish
/Gotchas
/Java
/Music
/NetBeans
/Sailfin

About Me

Photo of Vince Kraemer
Short Bio

Search

Links


Navigation



Subscribe with Bloglines Add to Technorati Favorites

Referers

Today's Page Hits: 214