Posted at April 11, 2020 / Carlos Chacin
In Effective Java, Joshua Bloch makes the following recommendation:
Classes should be immutable unless there’s a very good reason to make them mutable… If a class cannot be made immutable, limit its mutability as much as possible.
🔩 Immutable Objects
An object is considered immutable if its state cannot change after it is constructed. Maximum reliance on immutable objects is widely accepted as a sound strategy for creating a simple, reliable code. reference
- Immutable objects are constructed once, in a consistent state, and can be safely shared
- Will fail if mandatory attributes are missing
- Cannot be sneakily modified when passed to other code
- Immutable objects are naturally thread-safe and can therefore be safely shared among threads
- No excessive copying
- No excessive synchronization
- Object definitions are pleasant to write and read
- No boilerplate setter and getters
- No ugly IDE-generated
hashCode
, equals
and toString
methods that end up being stored in source control. reference
Read more ...
Posted at February 10, 2020 / Carlos Chacin
Read the English Version here
Java es un lenguaje orientado a objetos con algunos aspectos funcionales incluidos en su núcleo. Al igual que cualquier otro lenguaje orientado a objetos, las clases y los objetos son la base de cualquier funcionalidad que podamos escribir y usar. Las relaciones entre las clases / objetos permiten ampliar y reutilizar la funcionalidad. Sin embargo, la forma en que elegimos construir esas relaciones determina cuán modular, desacoplada y reutilizable es nuestra base de código, no solo en términos de nuestro código de producción sino también en nuestras suites de prueba.
En este artículo, vamos a describir el concepto de Inyección de dependencias en Java y cómo nos ayuda a tener una base de código más modular y desacoplada, lo que nos facilita la vida, incluso para las pruebas, sin la necesidad de ningún contenedor o marco sofisticado.
Read more ...
Posted at November 14, 2019 / Carlos Chacin
Lee la versión en Español aquí
Java is an object-oriented language with some functional aspects included in its core. Like any other object-oriented language, classes and objects are the foundations of any functionality that we can write and use. The relationships between the classes/objects make it possible to extend and reuse functionality. However, the way that we choose to build those relationships determine how modular, decoupled, and reusable our codebase is, not only in terms of our production code but also in our test suites.
In this article, we are going to describe the concept of Dependency Injection in Java and how it helps us have a more modular and decoupled codebase, which makes our lives easier, even for testing, without the need of any sophisticated container or framework.
Read more ...
Posted at December 21, 2015 / Carlos Chacin
There is a common requirement in most of the Java/JavaEE projects related to how differentiate environment configurations like development, test, QA, production, etc. for that reason there are a lot of frameworks or libraries to resolve that:
Even there is a Java Specification Request (JSR) Proposal:
Read more ...