Tag: Java

Why Good Code is Important?

Why Creating Good Code is Important?

Introduction Let’s be honest: there is a lot of really bad code out there. The tsunami of bad code cannot be overcome by the relative handful of gurus who have mastered code craftsmanship. Books become outdated, and the examples in training...

Observer Design Pattern with Java

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...

Proxy Design Pattern with Java

To make code flexible and easy to maintain we must find a way to encapsulate and not repeat the code. What if we need to do a specific treatment every time we get an Exception? Would we repeat this code in the entire application? We could, but...

Flyweight Design Pattern with Java

There are some situations in software development in which we need to improve performance. This is possible with the use of Cache. Imagine a lot of the same objects being created and wasting memory. The Flyweight pattern was created to avoid this...

Decorator Design Pattern

Decorator Design Pattern with Java

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...

Composite Design Patterns

Composite Design Pattern with Java

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...

State Design Pattern

State Design Pattern with Java

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...

Visitor Design Pattern

Visitor Design Pattern with Java

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...

Memento Design Pattern

Memento Design Pattern with Java

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...

Mediator Design Pattern

Mediator Design Pattern with Java

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...