Decorator
Don't confuse the decorator pattern with the concept of a Python decorator which we have gone through in Chapter 5, Using Decorators to Improve Our Code. There is some resemblance, but the idea of the design pattern is quite different.
This pattern allows us to dynamically extend the functionality of some objects, without needing inheritance. It's a good alternative to multiple inheritance in creating more flexible objects.
We are going to create a structure that let's a user define a set of operations (decorations) to be applied over an object, and we'll see how each step takes place in the specified order.
The following code example is a simplified version of an object that constructs a query in the form of a dictionary from parameters ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access