Excellent article, Thiago. Adding to the point, maybe, a recommended next step is to encapsulate it within a dedicated domain object, such as a Money class. This practice avoids Primitive Obsession and centralizes business rules, like currency rounding, in a single place resulting in a more type-safe and self-documenting API.
Excellent article, Thiago. Adding to the point, maybe, a recommended next step is to encapsulate it within a dedicated domain object, such as a Money class. This practice avoids Primitive Obsession and centralizes business rules, like currency rounding, in a single place resulting in a more type-safe and self-documenting API.
Thanks, this is also an excellent improvement.
There is also the JSR 354 — Money & Currency API https://javamoney.github.io/api.html to help to deal with Money.