Objects and slots

  • An object is made up of slots.
  • A slot can ba a method slot or a data slot.
  • Slot names are bound to message selectors.
  • A message bound to a method slot executes the method and returns its result.
  • A message, foo , bound to a data slot,
    foo returns the contents of the slot.
  • A message, bar : v, bound to
    an assignable data slot, bar assigns v to the slot.

Objects and slots

In Self, an object is made up of slots. A slot has a name and contains a reference to an object.
In Self, all of an object's state and behaviour is contained in its slots.

When a message is sent to an object, the name of the message (its selector) is matched against the slot of the same name, in a process known as message lookup. We will describe lookup in more detail later.

What happens in response to the message depends on the contents of the slot it is matched against. It could be a method slot or a data slot.

A slot is a method slot if it contains a method (an object containing executable code). In response to the message, the method is executed, and its result is returned.

A data slot just contains a reference to anything other than a method, i.e., any other kind of object. If a message matches a data slot, its contents are returned.

Data slots can be constant or assignable. A constant data slot, foo, responds to a message, foo, by returning the value in the slot. An assignable data slot, bar, responds to bar by returning the value in the slot, but also responds to bar: v by replacing its contents with v.

[ Previous ] [ Index ] [ Next ]