Persistent and transient objects - confused about terminology
Asked Answered
C

3

10

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

Cortex answered 12/7, 2012 at 18:41 Comment(0)
C
23

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.

Chappelka answered 12/7, 2012 at 23:56 Comment(2)
You answered my question, so I will mark it as answered in a day. But in case you find some time to help me some more: "No because value objects don't have an identity and can only be persisted as part of an entity or aggregate root."We don't use the two terms for Value Object even if it has its own database table?Cortex
An ORM determines the persistent/transient status of an object based on the value of its identifier (or version). Given that value objects don't have an ID the ORM doesn't make that determination for value objects - all value objects are persisted through a root entity. If you persist value objects directly then they aren't truly value objects.Chappelka
L
0

Transient means unprocessed object or the object which is instantiated or newly created. Once the object is being submitting for any other operation than the object state is known an persistent

Lucubration answered 19/12, 2015 at 7:45 Comment(0)
S
0

An object typically has two components: state (value) and behavior (operations).It can have a complex data structure as well as specific operations defined by the programmer.9 Objects in an OOPL exist only during program execution; therefore, they are called transient objects. An OO database can extend the existence of objects so that they are stored permanently in a database, and hence the objects become persistent objects that exist beyond program termination and can be retrieved later and shared by other programs. In other words, OO databases store persistent objects permanently in secondary storage, and allow the sharing of these objects among multiple programs and applications.

Spaetzle answered 24/12, 2018 at 23:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.