Somasundaram Sekar
Somasundaram Sekar

Reputation: 5524

DDD - Why are the identities of entities not just a primitive type?

What is the purpose of having the Id of an entity defined as custom type rather than as primitive, as database driven programmers usually do?

Upvotes: 2

Views: 321

Answers (1)

Backs
Backs

Reputation: 24903

First of all, Domain entities must be designed independant from storage (other question is that sometimes it's impossible, but let's assume this). In real world (or in domain world) entites often has complex identity like first name, last name and password number. It's not a primitive. People don't have an int Id from thier birth, but they have names and other documents. So, you need to translate it to your domain model. Of couse, sometimes, you don't have such complex identity and you can replace it with some more simple, like int number. But in both cases your choice shouldn't be based on database if you try to use DDD (it's difficult, yes). And later, you create mapping from domain entities to tables or other storage.

Upvotes: 3

Related Questions