Last updated at 4:59 am UTC on 19 July 2018
A Class is a special object that creates other objects (called its instances) in ObjectMemory. Notice the recursion here. Class objects are themselves created by Metaclass. The recursion stops at a special singleton ProtoObject.
A class defines the structure and behavior of it's instances.
It holds a collection of the names of instance variables that constitutes it structure and a MethodDictionary, mapping messages to Method Statements. These methods are precisely what is updated when you accept code in the code pane. This dictionary is also where the virtual machine looks for the code to run for a message.
Inspect these code snippets:
Classes take care of lots of details like helping to populate the object graph in the system and keeping track of variables known to all the classes' instances. Every class object is bound to a name in a global dictionary named Smalltalk:
Compare the following code:
(Smalltalk at: #Point) inspect
Many of the most important things classes know, they inherit from their superclass Behavior.
It is Behavior that holds the method dictionary, and keeps track of the classes' superclass (see Inheritance).
Playing with Behavior is one of the ways that Squeak lets us do radical things like playing with other representations of objects (for example, Objects without classes - aka, prototype systems).
After you're comfortable with classes, you should investigate Metaclasses. In a way, they're sort of "the Dark Side of the class". OTOH, they help classes be objects themselves.
From the Class comment:
This class adds a number of facilities to those in ClassDescription:
- A set of all subclasses (defined in ClassDescription, but only used here and below)
- A name by this class can be found in a SystemDictionary
- A classPool for class variables shared between this class and its metaclass
- A list of sharedPools which probably should be supplanted by some better mechanism.
The instances describe the representation and behavior of objects. More comprehensive programming support facilities are added to the basic attributes of Behavior and the descriptive facilities of ClassDescription.
The slot 'subclasses' is a redundant structure. It is never used during execution, but is used by the development system to simplify or speed certain operations.
See also How to get the class object if the name is given as a string
The term 'slot' is often used to refer to instance variables of an object. The term originates from the paper A Framework for Representing Knowledge by Marvin Minsky, MIT-AI Laboratory Memo 306, June, 1974. At that time, researchers were modeling intelligence from a perspective of small pieces. Marvin Minsky challenged them to start looking at things from a bigger perspective. He believed we have a ‘Frame’ which is the general shape of a chair. The Chair frame has ‘slots’ which represent details of the chair. The contents of a slot can be another ‘frame’.
In Smalltalk the Frame is analogous to a Class and a slot is somewhat analogous to an instance variable.
The Design Space of Frame Knowledge Representation Systems by Peter Karp