Tag: Java

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