From: Michael Walter Date: 2004-06-25T23:53:18+09:00 Subject: Re: Is it considered Harmful? Heya, Lennon Day-Reynolds wrote: > That's exactly the problem -- by forcing one object into another > class, you require that one or both classes have sufficient knowledge > of the internal data representation of the other to be able to safely > make the switch. That kind of low-level manipulation usually stays > within a class for a reason. That's why there are the _generic functions_ CHANGE-CLASS and UPDATE-INSTANCE-FOR-DIFFERENT-CLASS in Common Lisp. > The only real reason I can see to dynamically change the class of an > object would be in languages where there are static type constraints > that have to be satisfied. As it is, in Ruby, you can always just wrap > the original object in a proxy, or access it through an adapter that > supports all the public methods of the new class; it fits the "duck > typing" rule, without breaking encapsulation. Another reason would be that it might be useful to change the object _in place_. That is, all existing references suddenly point to the new object. Cheers, Michael