2 Comments
User's avatar
Anderson Caxeta's avatar

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.

Expand full comment
Thiago Bomfim's avatar

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.

Expand full comment