O'Reilly logo

Scala Design Patterns by Ivan Nikolov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required