The object model of Squeak is both simple and uniform. Everything is an object, and pretty much everything happens by message sends.
- Everything is an object. Primitive entities like integers are objects, but also classes are first-class objects.
- Every object is an instance of a class. Classes define the structure of their instances via private instance variables and the behaviour of their instances via public methods. Each class is the unique instance of its metaclass. Class variables are private variables shared by the class and all the instances of the class. Classes cannot directly access instance variables of their instances, and instances cannot access instance variables of their class. Accessors must be defined if this is needed.
- Every class has a superclass. The root of the single inheritance hierarchy is
ProtoObject. Classes you define, however, should normally inherit from
Objector its subclasses. There is no syntax for defining abstract classes. An abstract class is simply a class with an abstract method — one whose implementation consists of the expression
self subclassResponsibility. Although Squeak supports only single inheritance, it is easy to share implementations of methods by packaging them as traits.
- Everything happens by message sends. We do not “call methods”, we “send messages”. The receiver then chooses its own method for responding to the message.
- Method lookup follows the inheritance chain;
selfsends are dynamic and start the method lookup again in the class of the receiver, whereas
supersends are static, and start in the superclass of class in which the
supersend is written.
- There are three kinds of shared variables. Global variables are accessible everywhere in the system. Class variables are shared between a class, its subclasses and its instances. Pool variables are shared between a selected set of classes. You should avoid shared variables as much as possible.