6.3: Every Object Is an Instance of a Class

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.

    6.3: Every Object Is an Instance of a Class

    Every object has a class; you can find out which one by sending it the message class.

    1 class
    >>> SmallInteger
    
    20 factorial class
    >>> LargePositiveInteger
    
    'hello' class
    >>> ByteString
    
    (4@5) class
    >>> Point
    
    Object new class
    >>> Object
    

    A class defines the structure of its instances via instance variables, and the behavior of its instances via methods. Each method has a name, called its selector, which is unique within the class.

    Since classes are objects, and every object is an instance of a class, it follows that classes must also be instances of classes. A class whose instances are classes is called a metaclass. Whenever you create a class, the system automatically creates a metaclass for you. The metaclass defines the structure and behavior of the class that is its instance. 99% of the time you will not need to think about metaclasses, and may happily ignore them. (We will have a closer look at metaclasses in Chapter : Classes and Metaclasses.)


    This page titled 6.3: Every Object Is an Instance of a Class was last modified on Sat, 19 Dec 2020 08:13:44 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.