Name

Decorator

Also Known As Decorating Filter

Goal

Dynamically add functionality to the front controller (Figure A-1).

Classes in the Decorator pattern
Figure A-1. Classes in the Decorator pattern

Participants

Component

A common interface implemented by both decorators and the target.

Decorators

Encapsulate a piece of common functionality, such as decryption or logging, while presenting the same interface as the target.

Target

The final object in the request processing chain, coordinates all specific activities such as input handling. Typically the front controller (Figure A-2).

Interactions in the Decorator pattern
Figure A-2. Interactions in the Decorator pattern

Interactions

The decorator intercepts all requests destined for target and performs a common function such as logging or decryption. The decorator then forwards the request to the next decorator in the chain, or the target if there are no more decorators.

Notes

In the J2EE presentation tier, decorators are typically implemented as servlet filters with a servlet as the target. Note that filters have a slightly different API than servlets.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset