Simon Vandemoortele wrote:

> Just out of curiosity: would you comment on the two alternative designs
> I mentioned in my previous reply ? (It is rather appropriate that the
> LotY should be Haskel.)

To be honest, I'm not sure anyone can comment on alternative approaches 
without knowing the context: what is the problem that's being solved.

I'm not sure why you feel the immutable direction is cumbersome 
(although I probably wouldn't do it exactly the way you show.

>   myContact = myAddressbook.getContact('Simon Vandemoortele')
>   myContact = myContact.setAge(25)
>   myAddressbook.updateContact(myContact)
> 

My code might look something like:

   contact = book.mutable_contact_for_name('Simon Vandemoortele')
   contact.age = 25
   contact.save

I'm worried in your approach that it's too easy to lose the mutable 
object: on first sight

   myContact = myAddressbook.getContact('Simon Vandemoortele')
   myContact.setAge(25)
   myAddressbook.updateContact(myContact)

looks reasonable, but it discards the change.

So, I'd have a method in Contact that changes an immutable Contact into 
a mutable one. I'd also add factories in AddressBook that could return 
these directly. I'd then not even implement an 'age=' method in a 
immutable Contact class.

For simplicity I'd also have AddressBook set itself up as the backing 
store for Contacts it creates. That way you just have to write 
'contact.save' rather than carry both the Contact and AddressBook 
objects around throughout your code.




> PS: Since this is our first mail exchange I figure I am entitled to a
>     short I-read-your-books-and-loved-them-,-thanks-for-everything 
>     statement :)

Thank you!


Cheers


Dave