Patterns in Python – Behavioral
Behavioral patterns are the last stage in the complexity and functionality of patterns. They also come last chronologically in object life cycle in a system since objects are first created, then built into larger structures, before they interact with each other.
These patterns encapsulate models of communication and interaction between objects. These patterns allow us to describe complex workflows that may be difficult to follow at runtime.
Typically, Behavioral patterns favor object composition over inheritance as usually, the interacting objects in a system would be from separate class hierarchies.
In this brief discussion, we will look at the following patterns: Iterator, Observer, and State.
The Iterator pattern
An iterator provides a way to access elements of a container object sequentially without exposing the underlying object itself. In other words, an iterator is a proxy that provides a single method of iterating over a container object.
Iterators are everywhere...