[Seaside] Changing object class
bert at freudenbergs.de
Wed Oct 3 13:04:31 UTC 2007
There is #as: which copies all instance variables of the same name as
well as indexed variables to a new class. So you could say
numericRow := RowNumeric new.
totalRow := numericRow as: RowTotal.
As Sebastian wrote, this does not change the identity, you will have
both the numericRow and totalRow objects afterwards.
Instead, you could really change the original row's identity:
row := RowNumeric new.
row becomeForward: (row as: RowTotal).
And as others have noted the need for doing this is a sign of bad
design. Sometimes It's handy to be able to do this nonetheless ;)
- Bert -
On Oct 3, 2007, at 14:24 , Sebastian Sastre wrote:
> Smalltalkish how we function so..
> First of all it's really rare to have a real need of changing one
> object in
> place of another so I'll convice myself about other simpler options
> Do you need to preserve identity of the objects or data is enough?
> If data is enough you can make:
> ^ OtherThing fromSomeThing: self
> OtherThing class>>fromSomeThing: aSomeThing
> ^ self new
> prop1: aSomeThing prop1;
> prop2: aSomeThing prop2;
> that is enough?
> Sebastian Sastre
> PS: if identity is a must then you should investigate the #become:
>> -----Mensaje original-----
>> De: seaside-bounces at lists.squeakfoundation.org
>> [mailto:seaside-bounces at lists.squeakfoundation.org] En nombre
>> de Oleg Richards
>> Enviado el: Miércoles, 03 de Octubre de 2007 05:38
>> Para: seaside at lists.squeakfoundation.org
>> Asunto: [Seaside] Changing object class
>> Hello Guys!
>> Following question (maybe its a little bit "smalltalkish"):
>> I have an object - an instance of RowNumeric class. I also
>> have 2 classes derived from this class. Can i change instance
>> class from one derived to another without touching instance
>> So i have RowNumeric with all needed variables. And now i
>> want to convert some numeric rows to total ones.
>> Cheers, Oleg
More information about the Seaside