From the course: Spring: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

The Decorator pattern

The Decorator pattern

From the course: Spring: Design Patterns

Start my 1-month free trial

The Decorator pattern

- [Instructor] The Decorator Pattern is one of those patterns of composition that you either get or you don't but once you get it, its power becomes so great that you use it often within your development techniques. Within the Spring framework, decorators are used all over the place. The frameworks uses decorators to do much of its operations. Injecting your decorated objects, however, is difficult in Spring because of how bean references work specifically around shared interfaces. In order for you to use the decorators for your beans, you have to use Qualifier annotations which then makes your code less about IOC and more about you controlling the injection throughout your application. Now, the pattern and the way that it works in a nutshell is pretty straightforward. You add responsibilities to an object dynamically at runtime and you do so through composition instead of inheritance. Inherited base classes compose new behavior and responsibility by becoming additive or so-called…

Contents