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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.