↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Domain-Driven Design: Entities, Value Objects, and How To Distinguish Them

Entities and value objects are presented as basic building blocks of tactical DDD. The post explains that entities are defined by continuity and identity, while value objects have no conceptual identity and are defined by their attributes. It also argues that the choice depends on the domain.

Reading notes
#

  • Entities are for objects that need to be tracked over time and recognized as the same object even when attributes change.
  • A strong sign of an entity is a status-like attribute or a domain rule that requires matching by identity rather than by attributes.
  • Value objects describe characteristics of something and have no conceptual identity.
  • Value objects are treated as complex attributes of entities or other value objects.
  • Value objects should be immutable, so changing one attribute means creating a new instance.
  • The post recommends using value objects by default and assigning identity only when the domain requires it.
  • Entities use identity equality, while value objects use structural equality.
  • The example compares a Student entity by matriculation number and an Address value object by its fields.
  • Whether something is an entity or a value object depends on the domain, so the same concept can play different roles in different contexts.
  • An aggregate is a cluster of entities and value objects treated as one unit for changes, with one entity as the aggregate root.