Hi all, it seems like we cannot cast the class of object to its subclass if that subclass has had new instance variables added to it:http://forum.world.st/changing-the-class-of-an-existing-object-to-a-subclass-td4239041.html -- Siemen |
Siemen Baader <[hidden email]> wrote:
> > What else could I do, apart from removing the element from its tree, > creating a new (subclass) instance and then putting this element in place > of the old one? Some #perform or `super` magic..? Use composition? Generate accessing code where necessary. Is this very performance critical code? Stephan |
In reply to this post by Siemen Baader
Hi Siemen
IIRC this was known as "wide classes", there is some paper about it. Cheers, Hernán 2018-03-02 15:45 GMT-03:00 Siemen Baader <[hidden email]>: > Hi all, > > it seems like we cannot cast the class of object to its subclass if that > subclass has had new instance variables added to it: > > http://forum.world.st/changing-the-class-of-an-existing-object-to-a-subclass-td4239041.html > > But I (think) I need it - I'm transforming a DOM tree from XMLHTMLParser's > XMLElement s to a subclass of Iliad's ILHTMLBuilderElement s, and for single > occurences I would like to use the more specific subclasses, like > ILCheckboxElement. I can make the cast manually, I know when it is safe to > do. > > What else could I do, apart from removing the element from its tree, > creating a new (subclass) instance and then putting this element in place of > the old one? Some #perform or `super` magic..? > > hm.. > > thanks for any pointers! > > -- Siemen |
In reply to this post by Stephan Eggermont-3
"Castings" are aliens in the Smalltalk world, although there is a
#become*: method family, I would discourage you from using it as an alternative unless you really need to do it. If your use case is that concrete, I'd do something like: `ILHTMLBuilderElement fromXMLElement: anXMLElement` Then all subclasses of `ILHTMLBuilderElement` will know what to look and what to omit from the `XMLElement` parameter. Regards! Esteban A. Maringolo 2018-03-02 17:08 GMT-03:00 Stephan Eggermont <[hidden email]>: > Siemen Baader <[hidden email]> wrote: >> >> What else could I do, apart from removing the element from its tree, >> creating a new (subclass) instance and then putting this element in place >> of the old one? Some #perform or `super` magic..? > > Use composition? Generate accessing code where necessary. > Is this very performance critical code? > > Stephan > > > |
In reply to this post by Stephan Eggermont-3
On Fri, Mar 2, 2018 at 9:08 PM, Stephan Eggermont <[hidden email]> wrote: Siemen Baader <[hidden email]> wrote: Use composition? Generate accessing code where necessary. Hm yes.. This is probably what I'll end up doing eventually. I was trying to save a lot of typing work. XMLElement and ILHTMLBuilder both have useful interfaces, and some of it is called from behind the scenes by their respective frameworks. > Is this very performance critical code? I don't think so. But it is the HTML construction code of a web app, so it *might* become a bottleneck. I don't treat it like this ATM. Siemen
|
In reply to this post by Esteban A. Maringolo
On Fri, Mar 2, 2018 at 9:21 PM, Esteban A. Maringolo <[hidden email]> wrote: "Castings" are aliens in the Smalltalk world, although there is a Ok, thanks. I think this use case is specific enough for casting to be useful, but I see your point.
Yes.. :) -- Siemen
|
In reply to this post by hernanmd
On Fri, Mar 2, 2018 at 9:19 PM, Hernán Morales Durand <[hidden email]> wrote: Hi Siemen Thanks for the pointer! I found http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.31.4708 but no Pharo implementation. Was it available in Pharo at some point? cheers Siemen Cheers, |
Free forum by Nabble | Edit this page |