This repo contains an extraction of the Money
type from the TimeAndMoney library,
published by Eric Evans' company so long ago.
At the time (about 2004), standard Java did not provide a good implementation of time and date, so it made sense for others to provide them. Since tne introduction of LocalDate and related classes in Java 1.8 (2014), there is no need to use external libraries for dates and time anymore; there is, however, still a good case for implementing a Money abstraction.
Over the course of the years, I've seen various implementations of Money classes in the projects
I've been involved in, and they all more-or-less worked by wrapping Java's BigDecimal
, which is
not a very easy-to-use class. So I thought, why not go back to the work of recognized experts and
make it available in modern Java, unencumbered by the time and date parts of the original library?
What I did:
- Extracted the Money.java and MoneyTest.java files from the svn archive published on SourceForge
- Replaced uses of
com.domainlanguage.base.Rounding
with the corresponding values injava.math.RoundingMode
- Eliminated the default constructor and other methods that were "put in here begrudgingly" for the benefit of ORMs
- Updated tests to Junit 5, rewrote most assertions with AssertJ
- Moved
Ratio
from the packagecom.domainlanguage.base
tocom.domainlanguage.money
for cohesion
The code in this repo is Copyright (c) 2004 Domain Language, Inc. and published under the "MIT" license. See file LICENSE.