Design Pattern Intercepting Filter Pattern - Design Patterns

What is Design Pattern Intercepting Filter Pattern?

The intercepting filter design pattern is use when we want to do some pre-processing / post-processing with demand or response of the application. Filters are defined and apply on the request before passing the request to actual objective application. Filters can do the authentication/ authorization/ logging or tracking of request and then pass the requests to related handlers. Following are the entities of this type of design pattern.

  • Filter - Filter which will perform certain task prior or after execution of request by request handler.
  • Filter Chain - Filter Chain carries multiple filters and help to execute them in defined order on target.
  • Target - Target object is the request handler
  • Filter Manager - Filter Manager manages the filters and Filter Chain.
  • Client - Client is the object who sends request to the Target object.

Implementation

We are going to form a FilterChain, FilterManager, Target, and Client as different objects representing our entities.AuthenticationFilter and DebugFilterrepresent concrete filters.

InterceptingFilterDemo, our demo class, will employ customer to demonstrate Intercepting Filter Design Pattern.

interceptingfilter_pattern_uml_diagram

Step 1

Create Filter interface.

Filter.java

Step 2

Create concrete filters.

AuthenticationFilter.java

DebugFilter.java

Step 3

Create Target

Target.java

Step 4

Construct Filter Chain

FilterChain.java

Step 5

Create Filter Manager

FilterManager.java

Step 6

Create Client

Client.java

Step 7

Use the customer to demonstrate Intercepting Filter Design Pattern.

InterceptingFilterDemo.java

Step 8

Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Design Patterns Topics