© Jan Beernink and Arjan Tijms 2019
J. Beernink, A. TijmsPro CDI 2 in Java EE 8https://doi.org/10.1007/978-1-4842-4363-3_6

6. Decorators and Interceptors

Jan Beernink1  and Arjan Tijms2
(1)
Dublin, Ireland
(2)
Amsterdam, Noord-Holland, The Netherlands
 

The decorator pattern is a fairly commonly used design pattern. It allows one object to be wrapped by another so that the wrapping object can either extend or completely override its functionality.

Two good examples of the decorator pattern being used within Java are the InputStream and OutputStream classes. Wrapper classes, like BufferedOutputStream and FilteredOutputStream, add functionality to the OutputStream they wrap.

CDI supports the decorator pattern through decorators and interceptors. Decorators ...

Get Pro CDI 2 in Java EE 8: An In-Depth Guide to Context and Dependency Injection now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.