Open In App

Intercepting Filter Pattern

Preprocessing and postprocessing of a request refer to actions taken before and after the core processing of that request. Some of these actions determine whether processing will continue, while others manipulate the incoming or outgoing data stream into a form suitable for further processing. The classic solution consists of a series of conditional checks, with any failed check aborting the request. Nested if/else statements are a standard strategy, but this solution leads to code fragility and a copy-and-paste style of programming, because the flow of the filtering and the action of the filters is compiled into the application. The key to solving this problem in a flexible and unobtrusive manner is to have a simple mechanism for adding and removing processing components, in which each component completes a specific filtering action.

UML Diagram Intercepting Filter Pattern



Design components



Let’s see an example of Intercepting Filter Pattern.





Output:

Authenticating : Downloads
Log: Downloads
Executing : Downloads

Advantages :

Disadvantages :

If you like GeeksforGeeks and would like to contribute, you can also write an article using

write.geeksforgeeks.org

or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Article Tags :