<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>It's good to see you diving into these aspects of the system --
that's how you learn, and it's well worth learning.</p>
<p>Changing the superclass is, as the comment hints, in general a
dangerous operation. If you just assign a new value to the
superclass instance variable in the class and metaclass, that
changes the class hierarchy. But the new superclass might declare
different instance variables and/or class instance variables. So
now instances may not have the right instance variables, or even
the right number of instance variables. Depending on the
implementation of the VM, this could crash the system. It will at
least lead to incorrect behavior.</p>
<p>The safe way to change the hierarchy tends to go something like:</p>
<p>* Make a copy of the class and metaclass whose superclass is
changing.</p>
<p>* Compile all the methods defined by the class and metaclass on
the copied classes so that instance variable offsets are correct.</p>
<p>* Find all the instances of the class and metaclass. For each,
create an instance of the new class or metaclass, and copy the
common instvars over. Then send #become: to replace the old
instance with the new one.</p>
<p>* Then repeat all of the above for any subclasses of the class
whose superclass changed.</p>
<p>Development tools tend to do all of that for you transparently,
but don't let that fool you into thinking it's simple.</p>
<p>Regards,</p>
<p>-Martin</p>
<div class="moz-cite-prefix">On 11/27/25 1:47 PM, Facundo Javier
Gelatti wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAC1UKnZi6D5NRdMFLhScqbSSx1fjSiHEreKgzKRE24_vRt5rJQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div dir="auto">
<div>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.
<div>In that case, maybe I can add something to the method
comment, to avoid the confusion I had.</div>
</div>
<div><br>
</div>
<div>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::</div>
<div><span style="font-family:monospace">self class
superclass: self superclass class</span></div>
<div>and that makes my example work as I originally expected.</div>
<div>I find it interesting because encapsulation is preserved
while using a single message (with two different methods).</div>
<div><br>
</div>
<div dir="auto">Thanks Martin for your prompt and clear
response!</div>
<div>Cheers,</div>
<div>Facu</div>
<div dir="auto"><br>
<div class="gmail_quote" dir="auto">
<div dir="ltr" class="gmail_attr">El jue, 27 de nov de
2025, 18:15, Martin McClure <<a
href="mailto:martin@hand2mouse.com" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">martin@hand2mouse.com</a>>
escribió:<br>
</div>
<blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>Hi Facu,</p>
<p>I haven't looked at the code, but perhaps
#superclass: is a low-level method that just does
that one change. </p>
<p>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:.</p>
<p>Regards,</p>
<p>-Martin</p>
<div>On 11/27/25 12:42 PM, Facundo Javier Gelatti via
Cuis-dev wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>Hi!<br>
<br>
</div>
I've noticed that the #superclass: message does
not affect the superclass of the (meta)class of
the receiver. For example:<br>
<br>
<span style="font-family:monospace">Object
subclass: #A instanceVariableNames: ''
classVariableNames: '' poolDictionaries: ''.<br>
Object subclass: #B instanceVariableNames: ''
classVariableNames: '' poolDictionaries: ''.<br>
<br>
B superclass. " => Object "<br>
B class superclass. " => Object class "<br>
<br>
B superclass: A.<br>
<br>
B superclass. " => A "<br>
</span>
<div><span style="font-family:monospace">B class
superclass. " => Object class (not A
class)"</span></div>
<div><br>
</div>
<div>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).<br>
<br>
</div>
<div>Cheers!<br>
</div>
<div>Facu</div>
</div>
<br>
<fieldset></fieldset>
</blockquote>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</body>
</html>