Exploring the initial image: Class Object

The place to begin an exploration of the initial image is with the basic class Object, which is the parent class for all objects in the Smalltalk universe. That is, any object in the Smalltalk world will respond to the messages defined by the class Object.

We can divide the methods defined by class Object into four broad categories. There are those messages that deal with object identity and comparison (= == ~= isNil and notNil), those that deal with class description (class and printString), those that deal with class testing (isKindOf: isMemberOf: and respondsTo:) and finally those methods that will create windows of for various proposes (error: inspect edit and edit:).

Comparsion Methods: = == and ~= isNil and notNil

The most primitive method in the Smalltalk system is ==. This method tests whether the receiver is identically the same object as the value given to the right of the symbol. Since it returns a boolean (True/False) value, it is most often used inside a conditional expression:


(a == b) ifTrue: ['yes they are the same value']

If you look at the definition of this operation with the class browswer (see Browsing), you will see that this operation is defined by means of a primitive.


== arg
    " primitive object equality test"
    ^ <1 self arg>

Primitives, written as angle brackets, a primitive number, and a list of arguments, are basic system calls. The represent operations that cannot be performed in Smalltalk itself, and are instead provided directly in the Smalltalk interpreter. Object identity testing is primitive number 1.

The more common operation used to test equality (as opposed to identity) is the = method. If you examine this method in the initial image you will see that the default meaning is to use the identity operator. However, the equality testing operation is frequently redefined in many subclasses.


= arg
	^ self == arg

The ~= method is used to represent the concept of "not equal to". It is defined as testing equality, then inverting the result. This way if a subclass redefines the meaning of the equality operator, the not equal operator will be defined as well.


~= arg
	^ (self = arg) not

Finally, there are a pair of methods for testing nil and notNil. These simply return false and true, respectively.

Class access methods: class and printString

Asking an object what class it belongs to is also an extremely common operation. Once again this is not something that can be performed in Smalltalk itself, but is defined by a primitive operation (primitive number 2).


class   " get class of object "
	^ <2 self>

The default behavior for the method printString, which is intended to produce descritive information about an object, is to simply pass the message on to the objects class. Again, this method is frequently overridden by many classes.

printString
	^ self class printString

Class testing methods: isKindOf: isMemberOf: respondsTo:

There are several methods that use the ability to determine an objects class to find further information about an object. For example, the method isMemberOf: tests to see if an object is a member of a specific class:


isMemberOf: aClass
	^ self class == aClass

But an object can be an instance of a class through the process of inheritance. Hence the more general method isKindOf: walks up the class-parent class hierarchy, using the methods provided by class