Value Objects
Learn what value objects are and how they are implemented in Domain Driven Design.
We'll cover the following
As it was shown in the previous lesson, DDD has some tactical patterns to represent a model. There are three possible domain objects to implement business logic: Entities, Value Objects, and Aggregates. Consider creating an object that does not need identification such as an amount with value and currency. Value objects tackle just that.
Before going further with the definition of value object, it is worth looking at a common situation of the real world. It describes from the real world perspective what a value object is. Eric Evans mentions this situation in his book about Domain Driven Design: 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, its attributes define value objects. It means value objects do not have an ID, and they are identifiable by their set of attributes. That’s why these objects are immutable. Some common examples of value objects are Address, emailAddress, Amount. Everything depends on how the model was defined.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy