© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
V. SarcarJava Design Patternshttps://doi.org/10.1007/978-1-4842-7971-7_9

9. Decorator Pattern

Vaskaran Sarcar1  
(1)
Garia, Kolkata, India
 

This chapter covers the Decorator pattern, which is also known as the Wrapper pattern.

GoF Definition

It attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

Concept

An alternative to inheritance is composition. It is quite common in programming and often gives you a better payoff. This chapter shows a useful case study on this topic using some wrappers.

So, what is a wrapper(or a decorator)? A wrapper is like a topping that surrounds ...

Get Java Design Patterns: A Hands-On Experience with Real-World Examples 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.