Nested immutable value objects
"sudarshan89" <[email protected]>
| Newsgroups | gmane.comp.programming.domain-driven-design |
|---|---|
| Message-ID | <[email protected]> |
am trying to wrap my head around modelling with immutable objects, while doing so I am trying to understand how one would "update" a nested immutable object. I will just present my case with a help of an example, A car is filling fuel, this could be realized in code by creating a new car instance with a added fuel (keeping the immutable objects in mind, i do not just want to increment a counter) . So each time fuel is added I get a new car which has all the properties of the old car but the fuel tank has more fuel. This sounds conceptually good however we I try to code it down. My car would have a engine, tires and other immutable components, when a new car is created the entire graph needs to re created and then put into this new car, this would mean that i would need some kind of a copy constructor within my car class. I was curious to know how such a case can be handled cleanly ... Thanks ------------------------------------