[Cuis-dev] Behavior of #superclass: message

Facundo Javier Gelatti javiergelatti at gmail.com
Thu Nov 27 13:47:33 PST 2025


That makes a lot of sense. Maybe the meaning of the message is just that:
to change the superclass of the receiver and nothing else.
In that case, maybe I can add something to the method comment, to avoid the
confusion I had.

On the other hand, about the implementation possibilities (supposing we
wanted to implement it so that it did change the metaclass hierarchy), the
#superclass: message is currently implemented on Behavior and overridden in
Class. As the metaclasses include behavior from Metaclass and Behavior but
not from Class, then we could add this at the end of the method
Class>>#superclass::
self class superclass: self superclass class
and that makes my example work as I originally expected.
I find it interesting because encapsulation is preserved while using a
single message (with two different methods).

Thanks Martin for your prompt and clear response!
Cheers,
Facu

El jue, 27 de nov de 2025, 18:15, Martin McClure <martin at hand2mouse.com>
escribió:

> Hi Facu,
>
> I haven't looked at the code, but perhaps #superclass: is a low-level
> method that just does that one change.
>
> A higher-level facility might want to change the superclass in both the
> class and the metaclass, but it can't do that in one method because of
> encapsulation -- one method can't change the superclass instance variable
> in two different objects. So what message would it send to each of the
> class and the superclass? One logical selector to choose for that would be
> #superclass:.
>
> Regards,
>
> -Martin
> On 11/27/25 12:42 PM, Facundo Javier Gelatti via Cuis-dev wrote:
>
> Hi!
>
> I've noticed that the #superclass: message does not affect the superclass
> of the (meta)class of the receiver. For example:
>
> Object subclass: #A instanceVariableNames: '' classVariableNames: ''
> poolDictionaries: ''.
> Object subclass: #B instanceVariableNames: '' classVariableNames: ''
> poolDictionaries: ''.
>
> B superclass. " => Object "
> B class superclass. " => Object class "
>
> B superclass: A.
>
> B superclass. " => A "
> B class superclass. " => Object class (not A class)"
>
> The Class>>#superclass: method has a comment that says "Not to be used
> lightly!", so I'm not sure if this is in fact the expected behavior (but at
> least I was surprised by it).
>
> Cheers!
> Facu
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20251127/9a1cf8ef/attachment.htm>


More information about the Cuis-dev mailing list