When a client sends a request to the server, the server sometimes processes this request/response to perform the following tasks:
- Validating authentication
- Generating log
- Validating constraints
- Verifying the browser of the client
- Checking the duration between the request and response; calculating the response time
- Setting a cookie
However, we don't want to put these tasks within the logic of processing the main request.Consequently, creating a pre-process and/or post-process to do these tasks is a good method for decoupling the main logic from the complementary logic.
The intercepting filter pattern is the pattern that solves problems when we want to insert a logic that is not part of the main logic but we want to keep the two logics separated and decoupled. Merging the new logic with the main logic is a bad practice because these become coupled. This pattern creates a filter to pre-process and post-process the request, permitting the creation of a logic block...