Event-Driven Architectures

Skill Level:
Abstract

Using Factories of various abstractions, facades, and other patterns are not the only way to decouple dependencies and isolate code. A more idiomatic approach is events. All applications revolve around message passing. Passing bits to info within and outside of objects is the biggest job in any application. Message passing is typically accomplished using function and method calls. I send you a bit of information, you churn on it and send me something back and round and round we go.

Tight coupling happens because the code needs to have a live instantiation of another object so it can send it a message and maybe get a reply. These locally instantiated objects cause problems for coupling, modularity, and testability.

There is another way to pass messages to objects besides function calls: events. Javascript has excellent built-in native support for eventing thanks to the DOM.

Emitting events instead of making function calls obviously works best with global objects like utilizing AOP like logging, debugging, and code statistics that have no return values. However events can be used more deeply throughout a web application and we will see how events can play a much more centralized role in any web application.

Mark Ethan Trostler

I have been writing and testing code for over 20 years. From humble as a Computer Science/Philosophy double major at UC San Diego, to working at both startups (IPivot) and large corporations (Qualcomm, Intel, Redback Networks, Juniper Networks, and currently Yahoo!), I have always been dedicated to code quality. Currently as a Senior Principal Front End Engineer on the Yahoo Mail team, I help spearhead testing and quality for the latest rewrite of Yahoo Mail. I have spoken at several internal and
external conferences (Yahoo TechPulse 2010 and 2011, Yahoo’s Front End Summit, and at YUIConf 2011) about Testable Javascript and am the author of the Open Source Javascript Unit Test Environment (https://github.com/zzo/JUTE) and EventHub (https://github.com/zzo/EventHub).