What is entity domain model?

What is entity domain model?

As Eric Evans says, “an object primarily defined by its identity is called an Entity.” Entities are very important in the domain model, since they are the base for a model. Therefore, you should identify and design them carefully. An entity’s identity can cross multiple microservices or Bounded Contexts.

What does a domain model show?

The domain model is a representation of meaningful real-world concepts pertinent to the domain that need to be modeled in software. The concepts include the data involved in the business and rules the business uses in relation to that data. A domain model leverages natural language of the domain.

What makes a good domain model?

A good domain model controls the changes made to its information. This means that it should provide methods for manipulating its contents and prohibit all other changes to the information under its control.

Why are domain entities usually exposed as interfaces?

Interfaces are normally considered to be “contracts” and would therefore define behavior. The other major use is for mocking, so that you could provide domain entities that were mock-ups instead of coming from a specific data source (and having dependencies on that source).

Can a domain model be kept lean with exceptions?

However, from a DDD point of view, the domain model is best kept lean with the use of exceptions in your entity’s behavior methods, or by implementing the Specification and Notification patterns to enforce validation rules.

When do domain entities have to be valid?

Domain entities should always be valid entities. There are a certain number of invariants for an object that should always be true. For example, an order item object always has to have a quantity that must be a positive integer, plus an article name and price.

How are invariants enforced in the domain model layer?

Therefore, invariants enforcement is the responsibility of the domain entities (especially of the aggregate root) and an entity object should not be able to exist without being valid. Invariant rules are simply expressed as contracts, and exceptions or notifications are raised when they are violated.