Syntactic Compatibility. The decorated function can replace undecorated functions without modification of the codebase. This leads to two requirements:
The decorator doesn't add new input arguments, including new input args with default values.
The decorator doesn't change the returned data structure in case of successful execution of the undecorated function.
Decorators may alter the behaviour of a function in one or more ways:
Strengthening function preconditions. E.g. validate_arguments() throws new expections.
Weakening function postconditions. E.g. purrr::saftly + purrr::compose + Null object
Report additional information for function execution. E.g. print info in console or open intermediate results with View.
Modification of return values (not structure). E.g. rounding numeric values.
Decorators have the following qualities:
Decorators may alter the behaviour of a function in one or more ways:
validate_arguments()
throws new expections.purrr::saftly
+purrr::compose
+ Null objectprint
info in console or open intermediate results withView
.Decorators violate several SOLID principles: