Skip to main content
Engineering LibreTexts

12.2: Revisiting the Smalltalk Object Model

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)

    Since everything is an object, the color blue in Smalltalk is also an object.

    Color blue    →    Color blue

    Every object is an instance of a class. The class of the color blue is the class Color:

    Color blue class    →    Color

    Interestingly, if we set the alpha value of a color, we get an instance of a different class, namely TranslucentColor:

    (Color blue alpha: 0.4) class    →    TranslucentColor

    We can create a morph and set its color to this translucent color:

    EllipseMorph new color: (Color blue alpha: 0.4); openInWorld

    You can see the effect in Figure \(\PageIndex{1}\).

    A translucent ellipse.
    Figure \(\PageIndex{1}\): A translucent ellipse.

    By Rule 3, every class has a superclass. The superclass of TranslucentColor is Color, and the superclass of Color is Object:

    TranslucentColor superclass    →    Color
    Color superclass               →    Object

    Everything happens by message sends (Rule 4), so we can deduce that blue is a message to Color, class and alpha: are messages to the color blue, openInWorld is a message to an ellipse morph, and superclass is a message to TranslucentColor and Color. The receiver in each case is an object, since everything is an object, but some of these objects are also classes.

    Method lookup follows the inheritance chain (Rule 5), so when we send the message class to the result of Color blue alpha: 0.4, the message is handled when the corresponding method is found in the class Object, as shown in Figure \(\PageIndex{2}\).

    Sending a message to a translucent color.
    Figure \(\PageIndex{2}\): Sending a message to a translucent color.

    The figure captures the essence of the is-a relationship. Our translucent blue object is a TranslucentColor instance, but we can also say that it is a Color and that it is an Object, since it responds to the messages defined in all of these classes. In fact, there is a message, isKindOf:, that you can send to any object to find out if it is in an is a relationship with a given class:

    translucentBlue := Color blue alpha: 0.4.
    translucentBlue isKindOf: TranslucentColor    →    true
    translucentBlue isKindOf: Color               →    true
    translucentBlue isKindOf: Object              →    true

    This page titled 12.2: Revisiting the Smalltalk Object Model is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by Andrew P. Black, Stéphane Ducasse, Oscar Nierstrasz, Damien Pollet via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.