Does a domain object have to be persisted, or does this violate some convention about domain objects?

For example, let's say I'm using an object called AuthenticationState to represent authentication state in the application. This object has a boolean field isLoggedIn. I want to force the user to re-login each time so when I start the application again, I just create a new instance of the model with isLoggedIn set to false, instead of attempting to load one from local device/browser storage.

I feel like I may be overthinking things, but every example I've found online always has its domain objects use some sort of persistence. Is using domain objects in this way still acceptable?

  • isLoggedIn is presumably just one of the fields in a domain object. How do you propose that the system remember the other fields? Jan 15, 2021 at 3:24

1 Answer 1


I would say that the domain object has no relation to the persistence model you use in your application.

It's true that some of the web frameworks (like Rails for instance) would assume that every domain-level object could be persisted. But it's has nothing to do with the underlying principles of DDD. DDD in general defines the concept of Repository that is responsible for retrieving and storing the domain object. But the actual implementation might just create an object every time you want to retrieve it or read it from memory, or database. It's completely up to the developer.

Moreover, AuthenticationState could be hardly considered as a domain object. Please look at this SO answer:

Domain object an instance of a class that is related to your domain. I would probably exclude any satellite or utility objects from domain object, e.g. in most cases, domain objects do not include things like logging, formatting, serialisation, encryption etc - unless you are specifically building a product to log, serialise, format or encrypt respectively.

  • While I agree about the domain/persistence separation in general development terms, OP's question is a bit looser here. For example, when dealing with a windows app, we can consider whether an app that gets put to sleep can serialize its domain objects and restore them on application wake-up. That's not what "the persistence layer" commonly refers to, but it is a form of persistence of the domain objects inbetween application starts
    – Flater
    Jan 15, 2021 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.