- Intercepting Filter
- Forces
- Solution
- Consequences
- Related Patterns
Consequences
- Centralizes control with loosely coupled handlers
- Improves reusability
- Declarative and flexible configuration
- Information sharing is inefficient
Filters provide a central place for handling processing across multiple requests, as does a controller. Filters are better suited to massaging requests and responses for ultimate handling by a target resource, such as a controller. Additionally, a controller often ties together the management of numerous unrelated common services, such as authentication, logging, encryption, and so forth. Filtering allows for much more loosely coupled handlers, which can be combined in various permutations.
Filters promote cleaner application partitioning and encourage reuse. You can transparently add or remove these pluggable interceptors from existing code, and due to their standard interface, they work in any permutations and are reusable for varying presentations.
Numerous services are combined in varying permutations without a single recompile of the core code base.
Sharing information between filters can be inefficient, since by definition each filter is loosely coupled. If large amounts of information must be shared between filters, then this approach might prove to be costly.