Skip to content

Domain Model

  • The Domain Model is a conceptual model of the domain
  • A Domain Model is a representation of the relationships between the Entities and Value Objects in our Domain
  • The Domain Model should be recognizable and understandable by the business

Responsible for representing concepts of the business, information about the business situation, and business rules. State that reflects the business situation is controlled and used here, even though the technical details of storing it are delegated to the infrastructure. This layer is the heart of business software. (Eric Evans)

Entities

Entities are the "things" within your Model. An Entity is defined by being unique, and uniquely identifiable. The unique identity of an Entity can be provided by client, generated at construction time, or generated on persistence. It should be clear what is the role and responsibility of each entity.

Value Objects

Value Objects are the "things" within your model that have no uniqueness. They are equal in all ways to another Value Object if all their properties match Value Objects are interchangeable. Value objects are usually immutable.

Aggregates

The Aggregate is a cluster of domain objects that can be treated as a single unit. The Aggregate Root is the root item containing a number of parts that form a whole. The Aggregate Root can take care of keeping the aggregate in a consistent state. All business operations should go through the root.

Factories

Factories are responsible for encapsulating the logic of creating complex objects and aggregates. They ensure that an object or aggregate is created in a consistent and valid state.

Repositories

Repositories are used to retrieve aggregates from the underlying persistence layer. They provide an abstraction allowing the rest of the application to interact with the data store in a way consistent with the domain model.

Services

When an operation doesn’t logically belong to a value object or entity, it can be defined as a service. Services are part of the domain model and contain business logic that operates on the domain’s concepts. Services should be stateless with clear interface.