[Newbies] 'locking' an object

Sean Allen sean at monkeysnatchbanana.com
Thu Oct 2 18:55:34 UTC 2008


On Oct 2, 2008, at 1:18 PM, Bert Freudenberg wrote:

>> If you wanted to take a mutable object and make it immutable and be  
>> able to go back again to mutable,
>> how could you do that?
>
> What is your use case?

use case.

system needs to track changes to itself.

one option that has come up is...

linked list of different 'versions' of same object.
head is the live object. everything else past versions.

want to mutate object? you have to 'unlock'.
unlocking gives you a new copy and updates the linked list,
allowing all the accessors that mutate state to work.

when locked, calling one of those accessors would result in
an error. but when locked, read access still needed.

if i can find a way to put this in a superclass and have
children get the functionality w/o doing anything else,
then i really like it.

it cuts down on the 'real' programming as there are
many classes and many messages that need said functionality
and honestly, the disk space etc for the objects isnt a concern.

there are other options that have been looked at but all
require mucking about with each different class which ideally,
we want to avoid.



More information about the Beginners mailing list