Data Classes: Entities, Value Objects, DTOs, And Aggregates
Learn the different types of classes used to handle data. Find out the difference between an Entity and a Value Object. Understand what Aggregates are and when to use them.
It’s time to look at different data types and the differences between them. For each piece of data our code can store, it’s essential to know which type of data class matches it.
Entities
Entities are standalone things with persistent identities. Most of the things we manage are Entities—user records, blog posts, concerts, and reservations in a concert reservation app. The easiest way to spot an Entity is to see if it has an ID`` field or something similar.
Identity persists over time: We might change the property of an Entity, but it will be the same Entity. For example, if we edit a blog post, it’s still the same post.
Identity makes Entities individual: Two Entities can have the same properties but still be different. For example, if someone posts two identical comments to a blog post, they are still two different comments.
Example of an Entity definition
Here’s how a Reservation
Entity might look in the concert ticketing application:
Get hands-on with 1400+ tech skills courses.