15.2: Revisiting the Pharo Object Model

Pharo by Example 5.0 · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-SA 3.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    15.2: Revisiting the Pharo Object Model

    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 was last modified on Sat, 19 Dec 2020 08:13:45 GMT and 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.