Decorator
Learn about a structural design pattern: the decorator pattern.
We'll cover the following...
The decorator pattern is a structural design pattern. Don't confuse the decorator pattern with the concept of a Python decorator. There is some resemblance, but the idea of the design pattern is quite different.
Press + to interact
Usage of the decorator pattern
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 lets 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.
Working with an example
The following code example is a simplified version of an object ...