SOLID & Design Patterns Interview Question #69

What is an Entity in Domain-Driven Design?

Advanced Patterns, CQRS & Domain-Driven Design Fundamentals Mid-Level Intermediate

Quick Interview Answer

An entity is a domain object defined primarily by its identity and lifecycle rather than only by its attribute values. Two entity instances can represent the same conceptual object if they have the same identity.

Detailed Explanation

An entity is a domain object defined primarily by its identity and lifecycle rather than only by its attribute values. Two entity instances can represent the same conceptual object if they have the same identity.

Examples include Order, Customer, Employee, or Invoice when the business tracks each instance over time.

Code Example

public class Order
{
    public Guid Id { get; private set; }
    public OrderStatus Status { get; private set; }

    public void Confirm()
    {
        Status = OrderStatus.Confirmed;
    }
}