Wednesday, December 30, 2009

Publish-Subscribe Event Driven Programming

Publish-Subscribe messaging consists of loosely coupled system of topic/channel, publisher (provider), and subscriber (consumer).

Event Driven Programming allows the an objects to notify (i.e. publish an event) to observers.

Java programming model has long used the Observer/Listener pattern approach, and also Whiteboard pattern in OSGi environments.

However, there is no easy way and/or standardized convention to implement this.

Implementing the Observer pattern requires an object to extend Observable, which is "not POJO". Having listeners also clutter the class and there are a lot of boilerplate code to add:

private List<ClickListener> clickListeners = new ArrayList<ClickListener>();
private List<TouchListener> touchListeners = new ArrayList<TouchListener>();
public boolean addClickListener(ClickListener clickListener);
public boolean addTouchListener(TouchListener touchListener);
public List<ClickListener> getClickListeners();
public List<TouchListener> getTouchListeners();
public boolean removeClickListener(ClickListener clickListener);
public boolean removeTouchListener(TouchListener touchListener);
private void fireClick(ClickEvent clickEvent);
private void fireTouch(TouchEvent touchEvent);

See what I mean? That's only for two listeners, and those are only method signatures.

The implementation are probably trivial, but it's very boring to repeat these over and over again in most of your classes.

And what if the implementation isn't perfect? Will you change all those?

Over the next few posts, I'll explore the potential solutions.

1 comment:

coach factore outlet said...

Here we play with all sorts of influences - coach factory outlet of desired shapes tiffany jewelry to prioritize the tiffany and co manner in which I go about finding what I need," the coach factory outlet tells Ecouterre.More than 1,000 runners began the race.Not just in true religion jeans, but also in making sure you stay happy until the cheap jerseys rain every day. Hey, $350 is way less than those coach outlet. For those unfamiliar, the coach factory online (only the first coach factory count toward the rankings this year) in coach outlet online carry all their own alexander wang shoes for a daily water ration and michael kors outlet tent to sleep under;The coach factory outlet is yours, but coach factory outlet is to just be yourself and be coach outlet store online.The sleek ensemble came on show through sac burberry. Choose from brands like Bernardo, michael kors outlet and others.which saw everything he could to shake off that 'alexander wang bags' image, just got the treatment from the michael kors himself, marc by marc jacobs outlet department. the company was coach factory outlet online that it can really tell that you're turned on, so michael kors should definitely be saved for the bedroom.which has seen him take on projects from labels like michael kors outlet online, to things like designing boats.

Post a Comment

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