❖ In other words, an entity has an identity ❖ Changing an entity’s properties does not change its identity ❖ Examples ➢ A user of an application with authentication ➢ A product in an e-commerce store
identity ❖ Should be treated as immutable ❖ Two value objects with the same values are indistinguishable ❖ Changing a value object’s properties yields a different value object ❖ Example ➢ A copy of a game that got sold (assuming simple case where individual game copies are not tracked)
by a root entity known as the aggregate root ❖ Objects external to the aggregate can only hold reference to the aggregate root and nothing else in the aggregate ❖ Changes to the aggregate are done through the aggregate root to ensure consistency
belong to any object ❖ Examples ➢ A user purchases a product in an e-commerce application (ProcessTransaction) ➢ A new user registers in an application (RegisterUser) ➢ A user confirms an email verification (ConfirmUserEmailVerification)
DDD ❖ Mediator between application and data storage layers ❖ Solely responsible for fetching objects and persisting objects ❖ Exposes an interface that deals with object collections ❖ Usage is controversial with ORMs such as ActiveRecord
data access to the application ➢ No query builders in controllers and models! ➢ Consistent query logic when queries are reused ❖ Flexibility of using multiple persistence strategies without spilling that knowledge to the application ➢ ActiveRecord, Raw SQL, Redis, MongoDB, memory, CSV, etc. ➢ Easy to swap ORM or change DB
User can only be retrieved by ID, username or email ❖ Hide multiple data sources! ➢ SoA with multiple distinct databases ➢ Aggregate of objects persisted in different databases? More benefits of using repositories...