Value Objects

Learn what value objects are and how they are implemented in DDD.

As was shown in the previous lesson, DDD uses tactical patterns to represent a model. Consider the situation in which we need to create an object that does not need identification, such as an amount with value and currency. Value objects are useful in such cases.

Before going further with the definition of value objects, it is worth looking at a common situation of the real world. This example, taken from Eric Evans book on DDD, describes what a value object is from the real-world perspective:

“When a child is drawing, he cares about the color of the marker he chooses, and he may care about the sharpness of the tip. But if there are two markers of the same color and shape, he probably won’t care which one he uses. If a marker is lost and replaced by another of the same color from a new pack, he can resume his work unconcerned about the switch.”

What is a value object?

A value object is a representation of something that is involved in a business process. Unlike entities, value objects are defined through their attributes rather than an identifier. This means that value objects do not have an ID, and they are identifiable only by their set of attributes. Hence, these objects are immutable. Some common examples of value objects are Address, emailAddress, Amount, and so on.

Get hands-on with 1200+ tech skills courses.