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...
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...
What if we needed to create logs for all user actions on a project? Imagine if we repeated the same code for everything. The log would probably be like: Header – Always the same Body – Variable Bottom – Always the same Imagine if...
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...
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...
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...
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...
If you use Exceptions in the wrong way, bugs will be very difficult to find. If you always use generic Exceptions, how can other developers know what error has occurred? You have to understand why we use Exceptions and avoid Exception mistakes with...
The problem: lack of knowledge causes bad quality code. You won’t be able to implement the best solution if you don’t know, for example, the language, framework, or any other technology with which you work. You will probably reinvent the wheel many...
1 – Test business rules from your methods Well, what should be tested? Business rules, for sure! Don’t implement unitary tests to cover all methods and create numbers, make a real test! Know your method and test it with meaningful flows where you...