12.2 Cross-cutting concerns
One general principle behind decorators is to allow us to build a composite function from the decorator and the original function to which the decorator is applied. The idea is to have a library of common decorators that can provide implementations for common concerns.
We often call these cross-cutting concerns because they apply across several functions. These are the sorts of things that we would like to design once through a decorator and have them applied in relevant classes throughout an application or a framework.
Concerns that are often centralized as decorator definitions include the following:
Logging
Auditing
Security
Handling incomplete data
A logging decorator, for example, may write standardized messages to the application’s log file. An audit decorator may write details surrounding a database update. A security decorator may check some runtime context to be sure that the login user has the necessary permissions.
Our example of a null...