+ 6

What are the real advantages of using decorators?

5th Mar 2016, 8:15 AM
Martin Wild
Martin Wild - avatar
5 Antworten
+ 3
Omar : Can you explain what you mean by safe or danger event?
28th Jun 2016, 6:21 AM
Didier Cambier
Didier Cambier - avatar
+ 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)
9th Jan 2017, 5:27 AM
nate
nate - avatar
+ 2
Here is an example of what a decorator may be useful for: https://code.sololearn.com/cD09ijlIS6Ev/?ref=app
25th Mar 2018, 4:33 PM
Denys Yeromenko
Denys Yeromenko - avatar
+ 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
11th Mar 2016, 9:10 PM
Heather Brown
Heather Brown - avatar
- 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
3rd Apr 2016, 11:27 AM
Hashem Omar
Hashem Omar - avatar