Working with value objects
Value objects are, in some ways, the opposite of entities. With value objects, we want to assert that two objects are the same given their values. Value objects do not have identities and are often used in conjunction with entities and aggregates to enable us to build a rich model of our domain. We typically use them to measure, quantify, or describe something about our domain.
Before we go any further, let’s write some Golang code to help us understand value objects a bit further.
Firstly, we will define a Point
in the following code block:
package chapter3 type Point struct { x int y int } func NewPoint(x, y int) *Point { return &Point{ x: x, y: y, } }
We will also write the following test, which checks if two points with the same coordinates are equal:
package chapter3_test import ( &...