Do you remember how to use the Swing API with action events? If not, refresh your memory here: When using the Swing API you also use the Observer pattern maybe even without realizing it. The Observer pattern enables us to decouple the observed...
There are some situations in which we need high flexibility. Let’s consider that we want to create a flexible code for mixing a lot of different pizzas. We would not want to write all the possibilities without a pattern, right? For this...
Composing objects without a pattern can make code really messy – code repetition happens a lot and maintenance is terrible. Fortunately, there is the Composite design pattern that solves this problem completely. Using the Composite pattern we...
When it’s necessary to maintain the state from an object we can create a big code full of ifs controlling the State from the class. Certainly, this is not the right approach to solving this problem. Repetition of code is what we must avoid, we...
Sometimes we need to implement different methods for a POJO with different business requirements. We could certainly create several methods inside the POJO but we would not be utilizing the main benefits of powerful code – cohesion and low...
What if we need to keep many different states of an object? We could keep the information inside objects with a lot of setters and make the code a big mess. This would indeed work but it would be awful to change anything in the future. As we...
What should be done when we need to use a functionality that may be repeated in several classes? Should we repeat the code in all the classes? If the behavior of this functionality changes, you will be obligated to change it in the entire project...
Most of the time we use the Iterator from the Collections API. It’s very important to know how to implement a customized Iterator in order to understand what is happening behind the scenes. If we read Java source code, for example, we are...
Creating multiple methods inside only one class can bring many problems like inflexibility and difficulty maintaining code. I am sure all of us have already seen a class full of methods and different responsibilities, right? Classes like these are...
The problem: Sometimes we need to create complex objects based on abstractions and types. What can we do to deal with this problem? Create lots of “ifs”? No, we can use the Abstract Factory Pattern! Basically, with this Pattern we can...