Cross-cutting features and AOP
When we introduced the SOLID principles in Chapter 11, SOLID Principles, we discussed the Single Responsibility Principle. Based on this principle, a component must be focused on a single responsibility, that is, it has to implement the features that concern only a single aspect of the application. Often, however, in a complex application, we need cross-cutting features that can be intrusive and forced to enter in a component some code that is not strictly correlated with its specific goal. These features include, the following:
- Error handling
- Logging and tracing
- Authorization control
- Transaction control
These and other features are usually included in any application, but in most cases, they tend to pollute the code introducing unrelated logic.
The log management example
Let's analyze this problem with an example. Suppose we have a constructor function for objects having a method that makes the sum of two numbers:
function Calculator() {} Calculator.prototype...