They sound like two different objects to me , order and filled order . One of them is a copy of the other with an identifier ...
What do you think of the immutability you are interested in? How will this affect your domain model? For example, I saw that the "domain" objects have an id field to just go to sleep, but they will not have id values until hibernation gives them them. In this case, the domain object is weak.
Object model from a business perspective (in my academic example) assumes no identifier needed. However, an identifier is required for the model from a technical point of view (more specifically, hibernate wants one). There is clearly tension there, so I like clearly what I'm trying to model (business or technical).
Of interest, what does the identifier mean in your example?
So, when we think about the idea of identity (in the sense of Eric Evans), for an object or Entity to exist, it must have an identity ( Entities are equal if their identities are equal regardless of whether their contents are equal). For me it means
There is no point in a new version of Entity without identity (in this case, a id )
I also suggest
There is no such thing as an “almost” immutable object; it is either immutable or not
If you use the work described above, you must be sure that your object is no longer immutable. This may be good (again, why do you want immutability?). I don't think that having a domain object that can have a null for id (which is later replaced in the copy) is a good idea. This makes a “special case” that can be avoided by modeling it differently and opening up the possibility for you to handle a special case in many places (potentially).
source share