[Cuis-dev] relationship between Behavior, Object, and ProtoObject

Javier Pimás elpochodelagente at gmail.com
Wed Jul 17 06:53:47 PDT 2024


Actually, you cannot send new to _any_ object, just to instances of
Behavior (that implements new) and its subclasses (as with any
other message, no magic here). The question then is how come let's say
Object, which is not apparently linked anyway to Behavior,
answers `new`?

The answer there is in Object class, because it (and all of its superclass
chain) defines what messages Object can understand. You
can inspect `Object class withAllSuperclasses` to see the inheritance
chain.

The key insight here is that there is an artificial link hiding there, that
makes the whole thing *just work*: the superclass of ProtoObject
class. From the point of view of a developer looking at Class in a browser,
Class has no subclasses. However, it actually has one,
ProtoObject class.

The nicest thing is that you can just inspect ProtoObject class and Class
objects to see how they are internally linked (i.e look at Class
`subclasses` instance variable) until you clear all your doubts! And while
you can't directly access the VM lookup mechanism, you can
use an equivalent version implemented in Smalltalk, and debug the whole
process, with the expression `Object class lookupSelector: #new`

HTH, cheers!
Pocho

On Fri, Jul 12, 2024 at 10:31 AM Mark Volkmann via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> I understand that Object is a subclass of ProtoObject and that the
> `basicNew` and `new` methods are defined in Behavior. But I can't find a
> relationship between Object and Behavior, or between ProtoObject and
> Behavior. Can someone explain how it is that I can send `#new` to any
> object? How does it find that method in `Behavior`? I tried to use the
> debugger to discover the answer, but that didn't help me to find the answer.
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240717/3b2d66ff/attachment.htm>


More information about the Cuis-dev mailing list