We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Using Record Types to Build Better Domain Models by Henning Schwentner
Learn how to build a better domain model using record types, a new feature in Java 14, to define domain-specific value types and overcome object orientation limitations.
- Object orientation simulates the real world in software, but often struggles with complex domains.
- The problem with object orientation is that not everything in the real world is an object.
- Record types can help solve this problem by providing a way to define domain-specific value types.
- Record types can also help with primitive obsession, where code is cluttered with primitive types.
- In object-oriented programming, objects are typically mutable, which can lead to bugs and maintenance issues.
- Value types, on the other hand, are immutable, which can make them safer and more predictable.
-
Java has built-in value types like
int
andstring
, but not domain-specific value types like “amount” or “currency”. - To build a good domain model, you need to understand the domain and the objects within it.
- Record types can help build a more expressive domain model by allowing you to define domain-specific value types.
- Java 14 introduces record types, which can be used to define domain-specific value types.
- Record types are like value-based classes, but can be used in a more flexible way.
- Value types can be used to solve problems like primitive obsession and domain complexity.
- Record types are still reference types, but can be used in a way that feels like value types.
- In the future, value types will be a reality, and record types will be a way to use them.
- The author thinks that record types are a good idea because they can help build a more expressive domain model.