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!)
// 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?
No comments:
Post a Comment