5 popular decorators from Java

As a software developer, you probably know the Decorator Design Pattern, described in GoF. If not, read this first. Java has some nice decorators that can make your life easier, or tougher, depending on the case. Below, you will see a list of five decorators present in Java that you didn’t even realize they were decorations. java.util.Collections.synchronizedList(List list) Java 8 provides many synchronizedX() methods, for lists, sets, maps, etc. They are analog.

Read More

The Decorator design pattern in software development

A decorator is like a picture frame. It wraps the main object, adding some other functionality to it. The main goal of the Decorator pattern is to enable the addition of functionalities or behaviors dynamically to objects. To enable additional functionalities or behaviors in classes, a simple inheritance could easily do the job and no design pattern would be necessary. However, pay attention to the term “dynamically”. It means that the decorator must be instantiated after the original object already exists, and therefore inheritance couldn’t be the best solution.

Read More