Good Uses for Decorators
Learn some of the most common and relevant uses of decorators.
We'll cover the following...
Let's take a look at some common patterns that make good use of decorators. There are common situations for when decorators are a good choice.
Although there are countless applications that decorators can be used for, we will just enumerate the most common or relevant ones:
Transforming parameters: Changing the signature of a function to expose a nicer API, while encapsulating details on how the parameters are treated and transformed underneath. We must be careful with this use of decorators, because it's only a good trait when it's intentional. That means, if we are explicitly using decorators to provide a good signature for functions that had a rather convoluted one, then it's a great way of achieving cleaner code by means of decorators. ...