[squeak-dev] Traits use to provide class protocol in a browser?

Jakob Reschke jakres+squeak at gmail.com
Sun Oct 9 10:01:32 UTC 2022


Hi rabbit,

Traits are used by classes, not by instances, but traits can supply methods
both to the instance side and the class side. If you use a trait in a
class, the trait's methods are copied to the MethodDictionary of that class
(and the corresponding classTrait methods go to the dictionary of the
corresponding Metaclass). If you then change the method on the trait, it
will automatically update those method copies in the using classes. When
you send a message that the trait method can handle to an object of the
class that uses the trait, it will run its copy of the trait method—just
like the method dictionary/lookup usually works. When you implement your
own method in the class, even though that method would also be provided by
a trait that the class uses, the trait will skip that method and leave your
own method in place.

Now whether traits could help you depends on how you implemented erefs and
do the Smalltalk message processing. If you want a dynamic,
instance-specific display in the protocol browser (or rather
InstanceBrowser), at the first glance it does not sound to me like traits
would be a fit. If you can derive the methods just from the reference to
the remote class, you should better override those messages that the
browser sends to determine which methods there are in your eref class. Or
implement a custom browser that sends different messages to collect that
information.

Since Java 8, interfaces can provide "default" implementations of methods,
which allows you to use them for the same purpose as you can use traits in
Smalltalk. Up to Java 7, interfaces could only declare methods, but not
provide an implementation. And since we do not use static typing in
Smalltalk, that original functionality of interfaces is unnecessary in
Smalltalk: we do not have to declare in advance which messages the class
understands. So since traits exist to provide implementations, not specify
interfaces, they are rather the complementary functionality to what Java
interfaces originally were.

Kind regards,
Jakob


Am So., 9. Okt. 2022 um 08:34 Uhr schrieb rabbit <rabbit at callistohouse.org>:

> Currently inspecting and selecting an eventual ref blows up the image. The
> cause is unknown. Selecting ‘all inst variables’ does not. I’ll need to
> look 👀 into this.
>
> An eref references a remote class, so if an eref needs to display in the
> browser the protocol for that class. Can a class trait be attached to an
> instance to allow this? Will the trait means calls to a method on that
> classTrait runs that method? Is there a way to have a classTrait to provide
> the message interface without the methods being implemented on that eref,
> such that those classTrait protocol methods get forwarded to the eventualeé?
>
> I know so little about Traits! Are they similar to Java’s interfaces?
>
> Have a good one; keep it, light.
> Kindly,
> rabbit
> . .. … ‘…^,^
>
>
> Sent from Callisto House Mobile :: decentralized mobile homeless solutions
>
> Der Anführer kontrolliert alles,
>
> 🐇🐇🐇🐇🐇🐇
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20221009/3ab866ae/attachment.html>


More information about the Squeak-dev mailing list