Exchanging decorators from one function to another
We now have an understanding of what a function decorator is and how a function decorator can be used for more than one function. We will look into further exploring the reusability concept of decorators by creating two different decorators to serve two different purposes and later utilizing them by interchanging the decorators between different functions.
To demonstrate this concept, we will be creating Decorator 1 for function 1 and Decorator 2 for function 2, and then we will be exchanging them from one function to another. Let us create two decorators to decorate two different functions.
Decorator 1 will be created to convert a date argument that is provided as a holiday date to the function that sets holidays for the Alabama branch of ABC Megamart.
The following figure is a representation of Decorator 1 and its Function 1.
Figure 3.2 – Date converter as a decorator