Skip to content

fillmore-labs/value-comparison

Repository files navigation

Value Objects in Java

13a9640ff1e11890cfcfc26bde3dcc40ffd6617f062e67a35e badge maintainability

Demo code about value objects and how to create them in Java.

Purpose

This source demonstrates how to create value objects in Java using various annotation processors.

Evaluated Libraries

Also, simple record classes, Scala case class amd Kotlin data class examples are included for demonstration purposes.

Structure

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.

Running

Prerequisites

You need Bazelisk installed, see also Installing Bazel using Bazelisk.

macOS

Using HomeBrew enter

brew install bazelisk

Windows

Using Chocolatey enter

choco install bazelisk

Enable developer mode:

  1. Open Windows settings

  2. Go to “Update & security”, then “For developers”

  3. Under “Developer Mode” section enable “Install apps from any source, including loose files”.

or run with administrator privileges.

Main App

The main app simply demonstrates the toString() method with a simple structure. Run it with

bazelisk run //:value-comparison

Tests

To run all tests, use

bazelisk test //src/test/...

References