When the Timing of Identity Generation Matters

Identity generation can occur either early, as part of the object’s construction, or late, as part of its persistence. Sometimes it’s important to time identity generation early, and other times not. If it matters, we need to understand what’s involved.

Consider possibly the simplest case, that we can tolerate the late allocation of identity when a new Entity is persisted, that is, a new row is inserted in the database. This is demonstrated in the diagram in Figure 5.3. The client just instantiates a new Product and adds it to the ProductRepository. When the Product instance is newly created, the client doesn’t need its identity. And it’s a good thing, too, because the identity won’t exist then. ...

Get Implementing Domain-Driven Design now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.