Adobe Designer and Developer Lounge

a place where designers and developers can get to know one another

Greetings, all, from Denver. I've been following along with class since moving back, and got to thinking about Singletons and event dispatchers.

It seems a global event dispatcher could be a good idea, since there's only one to 'keep track' of. However, it seems many apps don't use this - they set up different dispatchers for custom events that different objects would be interested in.

I'm interested to hear if
1) anyone has used a singleton implementation of an event dispatcher
2) what you think the pros and cons of doing so would be

Things I can think of -

One pro - obviously, a centralized place that events useful to objects across an app can be dispatched

One con - in a very large application, you could start having collisions in terms of custom event names (ie, how many things do you need to keep track of that are all clicked on, using a similar click event).

I think that using a singleton disptacher or multiple dispatchers depends on, like everything else, the needs of your particular project.

Unrelated attachment... the recipe to the chocolate/almond candies I brought in December!

Signing off from the Mile High City!

Share

Attachments:

Reply to This

Replies to This Discussion

This is a good point. Remember, I'm teaching what I'm calling the "hierarchical" design in class. This isn't the most robust design for an application that you can get... it's really just a starting point even though it will work pretty well for many applications up to medium size.

There are other architectural frameworks out there for handling more complicated applications, but they tend to be pretty difficult to wrap your head around at first. Two frameworks that are really popular right now are Cairngorm and PureMVC. I'm afraid that I'm not really going to have time to go over either of these, but they use a fairly complicated event system to communicate between the different parts of an application. The base concept is similar to a singleton EventManager in that there is a single mechanism for dispatching application-wide events, but these frameworks go a lot further.

Of course, you can always set up mini eventManagers for sub-sections of your application, and you can add event listeners to individual Objects. All these levels of event management are very useful depending on the situation. Just remember that your main goal in application design is to 1) get things to work 2) make sure you reduce dependencies as much as necessary. Events of all types are crucial for both of these objectives.

Thanks for the research!

Daniel

Reply to This

RSS

© 2009   Created by Brad Tollefson on Ning.   Create a Ning Network!

Badges  |  Report an Issue  |  Privacy  |  Terms of Service