+ 6
What are the real advantages of using decorators?
5 Antworten
+ 3
Omar : Can you explain what you mean by safe or danger event?
+ 2
Think about the "extend" concept in Java/C++, Decorators is the simple version of "extend" , the biggest diff is you can not override the functionalities of the parent class(i mean the param func). For example, you have a generic function BasicEmailValFunc(str) which validates email address , which validates the input str has to be in XXX@XXX.XXX format, as per the new requirement ,you need the email has to be sent from a sepecific stmp server, like @myinc.com, you could do a furthur validation in decorator function meanwhile you will not need to duplicate the code from the BasicEmailValFunc(str)
+ 2
Here is an example of what a decorator may be useful for:
https://code.sololearn.com/cD09ijlIS6Ev/?ref=app
+ 1
Heather Brown
one way could be it enhances other functions that may get errors when ran on their own, or enhances a group of functions simultaneously instead of going into each function
- 1
what i think of is that...if func is an error msg...and something happened that changes the error msg from safe to danger...you need func to print danger...you can use decorators to change the output of the funtion func which you call to check on safety