Chapter 8. Observer Pattern

It is the theory that decides what can be observed.

Albert Einstein

Every man who observes vigilantly and resolves steadfastly grows unconsciously into genius.

Edward G. Bulwer-Lytton (Author of the immortal line, “It was a dark and stormy night,” written while trying to explain how his Internet connection got knocked out and he missed a deadline.)

The world is full of obvious things which nobody by any chance ever observes.

Sherlock Holmes (Original reference to syntax errors.)

You can observe a lot just by watching.

Yogi Berra

What is the Observer Pattern?

Conceptually, the Observer design pattern is easy to understand. A central point sends information to subscribing instances. This works just like a newspaper or cable television subscription service. When a person subscribes, the service begins, and continues until he unsubscribes.

In applications where a single source of information needs to be broadcast to several different receptors, using a single source in the design makes more sense than having several different sources getting the same information by repeated calls to the data source. For example, in using a web service that sends out stock quotes, setting up your application to receive the information in a single source, and then sending out that information from that source in your application, is more efficient than having each instance calling the information separately from the web service. If your application takes the incoming stock information ...

Get ActionScript 3.0 Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.