Possible way to achieve lazy loading with const objects
Marco Leise
Marco.Leise at gmx.de
Thu Sep 29 11:50:18 PDT 2011
Am 29.09.2011, 10:12 Uhr, schrieb Peter Alexander
<peter.alexander.au at gmail.com>:
> Why would a car be able mutate it's vendor?
A car is a passive object, that's obvious. Of course it doesn't mutate the
vendor and if it did, *mutate* doesn't mean the vendor can be robbed by
the car or something. The vendor class still has it's encapsulation and
invariants.
My point here is, that it is just the straight forward way to get that
information about a car. The vendor itself doesn't need to have a
reference to the car any more. It comes handy if I look at the car of my
neighbor and want to buy from the same vendor who's address is printed on
the license plate. The fastest way to implement that in a computer is a
simple mutable pointer. Mutable, because when I buy from the vendor it has
to change it's internal state.
The next best solution I can imagine is an external meta data table for
cases like this. It would be a hash map that holds a CarMetaData struct
for each car pointer with whatever is not part of the state of a car in
the close sense.
More information about the Digitalmars-d
mailing list