Tag: Java

Iterator Design Pattern

Iterator Design Pattern with Java

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

Facade Design Pattern with Java

Facade Design Pattern with Java

Sometimes we have to deal with complex methods where there are many processes and it’s necessary to orchestrate them every time and repeat the code many times. There are other situations in which the methods are very confusing and difficult to...

Prototype Design Pattern with Java

The Problem: We could solve the Prototype problem in an easy way, but we would have to write several setters and create a converter that passes all the information from getter to setter. For example: We can’t assign the object reference...

String pool challenge

Java Challenge #1: String Pool

Every time we create a different String, an object is created in the pool. How many objects were created in this situation? Try to solve this challenge before seeing the answer below. Answer: 3 Strings and 1 StringBuilder are created in the...

Singleton Design Pattern with Java

The problem: Imagine if we always had to create new instances for expensive objects, like DatabaseConnectors or Loggers, and use them in many places in the system. Imagine all the wasted memory. You could easily have a memory leak and your system...

Builder Design Pattern with Java

The Problem: Not using the right pattern for the right situation and creating difficult-to-find bugs. In day-to-day work I continually see complex objects being constructed without any patterns at all. What happens? Well, we see giant Services with...