Previous Table of Contents Next


The message yourself simply returns its receiver. This message is most commonly used at the end of a sequence of cascaded messages to access the cascaded receiver. Here’s an example:

  a := (Array new: 2)
          at: 1 put: ‘a’;
          at: 2 put: ‘b’;
          yourself.

The protocol <classDescription> defines the essential behavior of all class objects. It is also the protocol supported by the object that is the result of sending the message class to any object. It primarily provides messages that identify a class’s position in a class hierarchy. <classDescription> conforms to the <Object> protocol. Thus any object that conforms to <classDescription> also support all the messages specified in <Object>.

The protocol named <instantiator> defines the most common message for creating a new instance of a class. The standard class object with the global name Object conforms to <classDescription> and <instantiator>. Instances of Object conform to <Object>:

Protocol <classDescription> Conforms to: <Object>
Messages:
allSubclasses^<sequenceReadableCollection> Returns allsubclasses of a class
allSuperclasses^<sequencedreadableCollection> Returns all superclasses of a class
name^<string> Returns class name of the receiver class
subclasses^<sequencedReadableCollection> Performs a negated test for equality
superclasses^<classDescription> Returns the immediate superclass

Protocol <instantiator>
Messages:
new^<Object> Creates a new object

Protocol <Object class> Conforms to: <Object>, <instantiator>

The message name is used to obtain a textual description of a <classDescription>. If the receiver is a class object (or the result of sending class to an instance of a class), the description is the global name of the class. If the receiver is the result of sending the message class to a class object, the description is the global name of the class followed by the word class:

  Object name
      ‘Object’
  Array class name
      ‘Array class’

Any <classDescription> identifies a position in the class hierarchy. The message superclass returns a <classDescription> of the class from which objects described by the receiver directly inherit. The message allSuperclasses returns a collection of all superclasses of the receiver. The message subclasses returns a list of all the immediate subclasses of a class while allSubclasses returns a collection of all classes that inherit from the receiver, either directly and indirectly:

  Object superclass
      nil “Object does not inherit from anything”
  Object allSuperclasses
      #( )    “an empty collection”
  Customer superclass
      Object

The protocol <boolean> specifies the behavior of the objects true and false. If defines the basic operations of boolean algebra as well as “short-circuited” boolean operations. <boolean> also defines the conditional execution messages. <boolean> conforms to <Object>, so all the <Object> message can also be sent to <boolean> objects:

Protocol <boolean> Conforms to: <Object>
Messages:
& <boolean> ^ <boolean> Logical and
| <boolean> ^ <boolean> Logical or
and: <block0> ^ <boolean> Short-circuited and
eqv: <boolean> ^ <boolean> Logical equivalence
ifFalse: <block0> ^<Object> False conditional execution
ifFalse: <block0> ifTrue: <block0> ^<Object> Reversed-order conditional
ifTrue: <block0> ^<Object> True conditional
ifTrue: <block0> ifFalse: <block0> ^<Object> Normal conditional
not ^ <boolean> Logical negation
or: <block0> ^ <boolean> Short-circuited and
xor: <boolean> ^ <boolean> Exclusive or

The logical operations all have their conventional meanings. The conditional messages were explained earlier in the discussion of control structures. The short-circuited boolean operations make use of blocks to defer execution of their second arguments. The argument blocks should return <boolean> objects:

  (a size >= 4) and: [(a at: 4) = something]
  obj fastTestwithFalseNegatives  or: [obj slowerAcurateTest]

The instances of some classes represent ordered values. The protocol <magnitude> defines a set of messages for testing the ordering of such objects:

Protocol <magnitude> Conforms to: <Object>
Messages:
< <magnitude> ^ <boolean> Tests whether receiver less than the argument
<= <magnitude> ^ <boolean> Tests whether receiver less than or equal to the argument
> <magnitude> ^ <boolean> Tests whether receiver is greater than the argument
>= <magnitude> ^ <boolean> Tests whether receiver is greater than or equal to the argument
between: <magnitude> and: Tests whether within a range
<magnitude> ^ <boolean>
max: <magnitude> ^ <magnitude>
Determines the larger of the receiver and the argument
min: <magnitude> ^ <magnitude> Determines the smaller of the receiver and the argument

Because <magnitude> conforms to <object>, any object that supports the <magnitude> protocol supports the messages #= and #~=. Classes of objects that polymorphically support the <magnitude> protocol include the numeric objects as well as characters. The receiver and argument of these messages must be comparable values. Any two numeric objects may be compared, even if they are instances of difference classes. Similarly, any two characters can be compared. However, a numeric object cannot be compared to a character object.


Previous Table of Contents Next