Skip to main content
Engineering LibreTexts

15.2: Revisiting the Pharo Object Model

  • Page ID
    39662
    \( \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}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Rule 1. Since everything is an object, an ordered collection in Pharo is also an object.

    OrderedCollection withAll: #(4 5 6 1 2 3)
    >>> an OrderedCollection(4 5 6 1 2 3)
    

    Rule 2. Every object is an instance of a class. The class of an ordered collection is the class OrderedCollection:

    (OrderedCollection withAll: #(4 5 6 1 2 3)) class
    >>> OrderedCollection
    

    Rule 3. Every class has a superclass. The superclass of OrderedCollection is SequenceableCollection and the superclass of SequenceableCollection is Collection:

    OrderedCollection superclass
    >>> SequenceableCollection
    
    SequenceableCollection superclass
    >>> Collection
    
    Collection superclass
    >>> Object
    

    Let us take an example. When we send the message asSortedCollection, we convert the ordered collection into a sorted collection. We verify simply as follows:

    (OrderedCollection withAll: #(4 5 6 1 2 3)) asSortedCollection class
    >>> SortedCollection
    

    Rule 4. Everything happens by sending messagess, so we can deduce that withAll: is a message to OrderedCollection and asSortedCollection are messages sent to the ordered collection instance, and superclass is a message to OrderedCollection and SequenceableCollection, and Collection. The receiver in each case is an object, since everything is an object, but some of these objects are also classes.

    Rule 5. Method lookup follows the inheritance chain, so when we send the message class to the result of (OrderedCollection withAll: #(4 5 6 1 2 3)) asSortedCollection, the message is handled when the corresponding method is found in the class Object, as shown in Figure \(\PageIndex{1}\).

    class message send in a SortedCollection.
    Figure \(\PageIndex{1}\): Sending the message class to a sorted collection.

    This page titled 15.2: Revisiting the Pharo Object Model is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.