What is an Entity?
In Domain-Driven Design (DDD), an Entity is a fundamental concept that represents an object with a distinct identity that runs through its lifecycle. Here’s a breakdown of its key aspects:
1. Identity: Each Entity has a unique identifier, often called an ID. This identifier ensures that the Entity can be distinguished from other Entities, even if their attributes are the same.
2. Lifecycle: Entities have a lifecycle that includes creation, modification, and eventual deletion. They persist through different states and are often stored in databases or other forms of persistent storage.
3. Mutability: Unlike Value Objects (another DDD concept), Entities can change their attributes over time while retaining their identity.
4. Equality: Equality of Entities is based on their identity, not their attributes. Two Entities are considered the same if they have the same identifier, regardless of their attribute values.
For example, in an e-commerce system, a `Customer` could be an Entity. It has a unique ID (e.g., a customer number) and its attributes (name, email, etc.) can change over time. What makes it the same `Customer` is its unique ID, not its attributes.