Wednesday, December 30, 2009

Generics for Event Listener Pattern

To workaround the somethingListener -> somethingEvent mapping.

I'm not the first person to care about Event Notification. (but it's a problem that I'd rather not care about, especially after I met Qt's Signals and Slots... Java beaten by C++? Come on!)
    Maybe we can use Java 5 generics to save some code...
    // Common interface for all listeners. 
    public interface Listener<E> {
      public void notify(E event);
    }
    
    public class PedalEvent {
      // any custom properties wherever necessary
    }
    
    public class PedalListener implements Listener<PedalEvent> {
      public void notify(PedalEvent event) {
         // ... implementation ... 
      } 
    } 
    
    public class Car {
      public void addPedalListener(Listener<PedalEvent> pedalListener); 
      public void removePedalListener(Listener<PedalEvent> pedalListener); 
    } 
    
    
    What do you think?

    3 comments:

    Anonymous said...

    Keep sharing such ideas in the future as well. This was actually what I was looking for, and I am glad to came here! Thanks for sharing the such information with us.http://www.stevenlevinlaw.com |

    http://www.practicalenergylaw.com |

    http://www.phoenixlawpllc.com |

    http://www.parhamlawfirmllc.com |

    http://www.legallisted.com |

    http://www.legalizecookies.com |

    http://www.lawsonforflorida.com |

    http://www.immigration-lawyer-utah.com |

    http://www.florencefederallawyer.com |

    http://www.federal-trial-lawyer.com |

    coach outlet store online said...

    http://www.coachoutletstoreinc.com/ Coach Outlet Store Online

    http://www.michaelkorsoutletmkinc.com/ Michael Kors Outlet

    http://www.coachfactoryoutletwebsite.com/ Coach Factory Outlet

    http://www.tomsusashoes.com/ Toms Shoes

    http://www.cheapjerseysinc.com/ Cheap Jerseys

    http://www.michaelkors-bedford.com/ Michael Kors

    http://www.coachoutlet-sale.com/ Coach Outlet

    http://www.coachfactoryoutletorg.com/ Coach Factory Outlet

    http://www.coachoutlet-buy.com/ Coach Outlet

    http://www.coachhandbagsonlineoutlet.com/ Coach Handbags

    http://www.giuseppezanottionline.com/ Giuseppe Zanotti

    http://www.coachfactoryoutlet-handbags.com/ Coach Factory Outlet

    http://www.coach-factory-outlet-online.com/ Coach Factory Outlet Online

    http://www.coachstoreonline.com/ Coach Outet Store Online

    http://www.coachfactoryoutlets2014.com/ Coach Factory Outlet

    http://www.michaelkorsoutletonlinemk.com/ Michael Kors Outlet Online

    http://www.celineoutlet-online.com/ Celine Outlet

    http://www.michaelkors.name/ Michael Kors

    http://www.michael-kors-outlet-store.com/ Michael Kors Store

    http://www.tomsshoescompany.com/ Tomss Hoes

    http://www.pradaoutlet-store.com/ Prada Outlet

    http://www.fitflopfootwear.com/ Fitflop Footwear

    http://www.celinebags-outlet.com/ Celine Bags

    http://www.fitflopsflipflops.com/ Fitflops Flipflops

    http://www.fitflopusaonline.com/ Fitflops

    http://www.giuseppezanottidesigner.com/ Giuseppe Zanotti Designer

    http://www.fitflopflip-flop.com/ Fitflops

    http://www.giuseppezanottisneakersmen.com/ Giuseppe Zanotti Sneakersmen

    http://www.fitflopsandalssale.com/ Fitflops

    Nithyanantham M said...

    Thanks for sharing this post
    Dailymotion video downloader

    Try Dailymotion video
    downloader
    to download videos from dailymotion.

    Post a Comment

     
    Copyright 2009 Spring vs Java EE Web Dev. Powered by Blogger Blogger Templates create by Deluxe Templates. WP by Masterplan