From: Dave Thomas Date: 2003-05-01T03:07:54+09:00 Subject: Re: [OO interface design] Pass-by reference VS encapsulation ? Simon Vandemoortele wrote: > All this works wonderfully well but for one thing: once the addressbook > gives a *Contact* (actually a reference to *Contact*) to a client, the > client can modify the *Contact* (that is _inside_ the addressbook) > without the addressbook's knowledge. Is a Contact that you return as the result of a search(say) the same type of thing that you use to create or edit a new entry? You assumption is that they are (basically) the same thing, but perhaps you might want to rethink that. They don't seem to share the same methods. Maybe you need two classes: Contact and MutableContact. Regular Contact classes have methods that let them be examined but not altered. MutableContacts allow change. If needed by your application, class Contact could include a #to_matuable method that returned a MutableContact. Cheers Dave