From: Mikael Brockman Date: 2004-06-26T04:44:06+09:00 Subject: Re: Is it considered Harmful? Florian Gross writes: > Jim Weirich wrote: > > > Florian Gross said: > >> [problems with proxies] > > Comparisons are problematic because the first line of a comparison is > > often "Are you the same class as me?". Proxies arent't the right class so > > the comparisons fail. > > It depends -- the answer to that question can be overloaded in most > cases. (Though Object.instance_method(:class).bind(obj).call will > always give you the real class and I think that some of the internal > methods actually do something like that.) > > > Actually, rather than a become or class= method, I would be interested in > > a swap_identitys method. For example, to make a proxy object real ... > > def make_real > > obj = read_real_object_from_the_database > > swap_identities(self, obj) > > end > > When identities are swapped, every reference in the system to the > > first > > object will magically become a reference to the second object, and > > vice-versa. > > This is how Squeak implements this AFAIK -- it just iterates through > all Object references and changes them. > > I'm not sure, but this could be a bit slow, maybe. (And I'm not sure > if it would be a general solution for the problems with Proxy objects > -- it would work in the lazy database example, but there might be > other problematic use cases.) > How about changing the object to a redirection pointer, and also updating references in the garbage collector's root set traversal? You'd get some overhead at first, but after one garbage collection, all references will be updated and the redirection object can be recycled. mikael