Andreas Raab wrote:
One thing I am wondering about is whether anyone out there has been using Announcements for frameworks that have a larger number of events. The framework I applied it to ended up with some 30 events (the total number of classes in the framework is about 70, but it is event-heavy) which at first seemed excessive but it *is* the number of events that are being used so at least people can find out whether there is an event for a change of foo or not. In that sense my original intuition proved true (lots of classes but you do get to document the events in your system). I am curious how people feel about this proliferation of classes.
I used Announcements in OmniBrowser. There are 18 Announcement classes in my image, and maybe a few more floating around in other packages. I also use the pattern for another purpose, Command, which is the OmniBrowser mechanism for populating menus and buttons. The "browse senders of..." menu item, for example, is created by an instance of OBCmdBrowseSenders. In my image, there are 172 subclasses of OBCommand, and dozens more in packages I don't have loaded.
At first I was a bit skeptical about the explosion of classes. Even while I was implementing it, I thought of it as a bit of a hack - practical maybe, but inelegant. Since then I've decided I really like it. There *is* something inelegant there - too many named entities - but it's extremely easy to understand how Commands work and implement new ones.
The other thing that using Announcements extensively will probably force is name spaces. It seems impossible for two frameworks not to have a "ValueChanged" event. The precise definition of which will likely differ (for example, where I've been using it, it is critical that the signaler gets passed along with it; but I am certain there are some places where people don't want to pay for that slot).
Yeah. OmniBrowser already used 'OB' as a class name prefix, but even so, I prefixed command names with 'OBCmd'. I haven't run into any conflicts yet, but it feels cleaner that way.
In any case, I think announcements are a great improvement over the usual pattern of using event names instead of objects. You should definitely give it a try the next time you consider using an event framework.
I second this endorsement. Implementing Announcements (and Commands) for OmniBrowser vastly simplified things. This was a few years ago - here's what I wrote about it at the time:
http://www.wiresong.ca/air/articles/2006/06/11/announcements
Colin