The Observer pattern is mainly used to implement a distributed event handling system. The primary objective of this pattern is to provide a way to handle run-time one-to-many relationships between objects in a loosely coupled arrangement.
Oftentimes, you need to have objects that communicate with each other via events. This is a very useful setup, for example, in a GUI — where these events represent things like mouse clicks, key strokes, or button presses. That’s not what I developed these classes for, since I was more interested in simulating things and the event system seemed like the most natural fit, but the recipe is still relevant to other event handling needs. Continue reading “Event-based Programming for Python”