Blog: Classier Twitter threads - Tag Hibernate

Specialized Value Objects for entity identifiers

You’re probably already using Value Objects daily. Most likely, you’ve come across LocalDate, LocalTime, Instant, URL, Path, … etc. These are provided by the language and are very generic. Maybe you’ve written your own for something like an Email or PhoneNumber, but they’re still relatively generic and can have a lot of use-cases across your codebase, even if they’re specialized for your problem domain.

But, you can also have specialized VOs for single-place use, and there is nothing wrong with that. Thanks to the specialization, you can be extremely strict about the values you’ll allow, and you’re getting a level of type safety you would not get with plain strings or even generic VOs.

Continue reading ...