The value object design pattern

In programming, there are different ways of comparing data. We can compare object identities or their values. These are useful in different scenarios and here we will see what value objects are and when they can be used. Value objects are:

Note

Small and simple immutable objects. Their equality is based not on identity, but on value equality.

Value objects are used to represent numbers, money, dates, and so on. They should be small and immutable; otherwise, changing values could cause bugs and unexpected behavior. They are quite useful in multithreaded applications due to their immutability. They are also commonly used as data transfer objects in enterprise applications.

Class diagram

In languages such as Java, there ...

Get Scala Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.