Persistent and transient objects - confused about terminology

user1483278 picture user1483278 · Jul 12, 2012 · Viewed 22.1k times · Source

Here is my definition of the two terms, though I'm not sure if it is a complete one:

A persistent object is an instance of a class in the domain model that represents some information extracted from the database. A transient object is an instance of a class in the domain model, which is created in memory

a) I assume the terms persistent and transient are used only for objects in the domain model, but not also for objects in business layer that live outside the domain model?

b) Do we also use the two terms for Data-Transfer-Objects?

c) Are the two terms also used for Value Objects?

Thank you

Answer

eulerfx picture eulerfx · Jul 13, 2012

Persistent means that the object has been saved to the database whereas transient means that it hasn't been saved yet. So for example when you get an entity from a repository, that entity is persistent. When you create a new entity, it is transient until persisted.

a) These terms are more affiliated with ORMs than they are with DDD so they apply to anything that is not DDD. Within DDD persisted/transient apply to entities and aggregate roots because these are the objects that are persisted with repositories.

b) No, DTOs are designed to carry data across process boundaries and don't have a life-cycle that objects that you wish to persist to a database do.

c) No because value objects don't have an identity and can only be persisted as part of an entity or aggregate root. A value object is just a value, sort like 1 is a integer value and it doesn't make sense to speak about whether it is persisted or not.