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, Scala case class amd Kotlin data class examples are included for demonstration purposes.
In com.fillmore_labs.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.
com.fillmore_labs.talk.value.inheritance.*
and com.fillmore_labs.talk.value.composition.*
demonstrates
the composition over inheritance
principle and why value objects can not meaningfully extend each other.
You need Bazelisk installed, see also Installing Bazel using Bazelisk.
Using Chocolatey enter
choco install bazelisk
Enable developer mode:
-
Open Windows settings
-
Go to “Update & security”, then “For developers”
-
Under “Developer Mode” section enable “Install apps from any source, including loose files”.
or run with administrator privileges.
The main app simply demonstrates the toString()
method with a simple structure.
Run it with
bazelisk 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.