Skip to content

melsicon/value-comparison

Repository files navigation

Value Objects in Java

570f6859809a2a1ad1ef957dc6c25cc808d4827709d74391de

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 and Scala examples are included for demonstration purposes.

Structure

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.

Running

Prerequisites

You need Bazelisk installed, with HomeBrew just use brew install bazelbuild/tap/bazelisk. See also Installing Bazel using Bazelisk.

Main App

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

bazel run //:value-comparison

Tests

To run all tests, use

bazel test //...

References