Behavioral patterns
Behavioral patterns are intended to simplify the interactions between classes by structuring the processes of their interaction.
This section provides three examples of popular behavioral patterns that you may want to consider when writing Python code:
- Observer
- Visitor
- Template
Observer
The observer pattern is used to notify a list of objects about a state change of the observed component.
Observer allows adding features in an application in a pluggable way by de-coupling the new functionality from the existing code base. An event framework is a typical implementation of the observer pattern and is described in the figure that follows. Every time an event occurs, all observers for this event are notified with the subject that has triggered this event.
An event is created when something happens. In graphical user interface applications, event-driven programming (see http://en.wikipedia.org/wiki/Event-driven_programming) is often used to link the code to user actions. For instance...