Demo code about value objects and how to create them in Java.
This source demonstrates how to create value objects in Java using various annotation processors.
Also, simple record classes and Scala examples are included for demonstration purposes.
In de.melsicon.talk.value.simple.*
we have simple classes, one EmailAddress
which
demonstrates the power of being able to check value objects for consistency during construction and
Person
, which show how different libraries handle optional parameters and documentation
propagation.
de.melsicon.talk.value.inheritance.*
and de.melsicon.talk.value.composition.*
demonstrates
the composition over inheritance
principle and why value objects can not meaningfully extend each other.
You need Bazelisk installed, with HomeBrew
just use brew install bazelbuild/tap/bazelisk
.
See also Installing Bazel using
Bazelisk.
The main app simply demonstrates the toString()
method with a simple structure.
Run it with
bazel run //:value-comparison
-
Joshua Bloch. Effective Java, 3rd Edition. Addison-Wesley Professional. 2018.
-
Martin Odersky, Lex Spoon, Bill Venners. How to Write an Equality Method in Java. 2009
-
Dan Bergh Johnsson. Power of Value - Power Use of Value Objects in Domain Driven Design. QCon London. 2009.
-
Brian Goetz. Data Classes and Sealed Types for Java. 2019.
-
JEP 395. Records. 2020.