Patterns in Python – Structural
Structural patterns concern themselves with the intricacies of combining classes or objects to form larger structures, which are more than the sum of their parts.
Structural patterns implement this by these two distinct ways:
By using class Inheritance to compose classes into one. This is the static approach.
By using object composition at runtime to achieve combined functionality. This approach is more dynamic and flexible.
Python, by virtue of supporting multiple inheritance, can implement both of these very well. Being a language with dynamic attributes and using the power of magic methods, Python can also do object composition and the resultant method wrapping pretty well also. So, with Python, a programmer is indeed at a good place with respect to implementing structural patterns.
We will be discussing the following structural patterns in this section: Adapter, Facade, and Proxy.
The Adapter pattern
As the name implies, the Adapter pattern wraps or adapts an...