What exactly decorators do? any simplified definition of decorators and in what situation we need to use them?
Decorators, want a simplified definition of that
Hey @aswal.vandit_986431f1a630d4d8,
So basically decorators provide a simple syntax for calling higher-order functions. Higher order function are those function that takes function as an argument, or returns a function. So for doing this basically we pass a function in which extra features are to be used as an argument to another function then define a new function inside and then return a function. This process we have to do every time with or without decorator but after this in the calling of function decorator come in play. So what happens is while calling function first the function in which these extra features to be applied is passed as an argument to the new function we have made then a new variable is made to get the output of the function we have made which is another function, then now we to call explicitly that variable as an function as it contains the returned function. So to make this process easier decorators are used they just make the function in which we have to add extra features as the variable we have created so we don’t have to explicitly make new variables and reassign it instead we can just call the function directly in which extra features are to be added. And for doing this we have just use @thenewfunction on the function in which we have to add extra features.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.