Re: Re: Nested immutable value objects
Remy Fannader <[email protected]>
| Newsgroups | gmane.comp.programming.domain-driven-design |
|---|---|
| Message-ID | <CAMdXxPBV3z2rCbRNe2b_D0AOg98_vAmQUhLHOD6dPAN1ibhj6g@mail.gmail.com> |
A model for cars will be definitively different depending of what is managed. For instance, a tyre manufacturer may want to monitor the use of instances of cars and tyres in order to improve its models. Remy. On 19 March 2013 15:27, sudarshan89 <[email protected]> wrote: > ** > > > So does the Car class something like a copy constructor , where we give > all the old values of the car , along with a new value for Fuel .. while > constructing this new Car ? > > If we run with this Example of Car with 4 tires and Fuel ... Can you show > me how you're Car, Fuel and Tyre classes would look ? > > --- In [email protected], Giacomo Tesio <giacomo@...> > wrote: > > > > In C# I used delegate functions. > > > > Something like car.WithFluel(fluel => fluel.Increase(100)), with > > Car.WithFluel() returning a new Car, and Fluel.Increase returning a new > > Fluel. Car.WithFluel is responsible to mix the variation in the values. > > > > This works well as far as you don't have many levels of nested value > > objects: on the real world examples that I've met till now, I've needed > at > > most 3 levels, and no one encountered problems while reading the code. > Just > > remember to document all exceptions that each method does not handle (see > > > http://epic.tesio.it/2013/03/04/exceptions-are-terms-ot-the-ubiquitous-language.html > > ). > > > > > > Giacomo > > > > On Tue, Mar 19, 2013 at 7:19 AM, sudarshan89 <sudarshan89@...> wrote: > > > > > ** > > > > > > > > > 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 > > > > > > > > > > > > > >