Go to the first, previous, next, last section, table of contents.


Objects, classes and instances

Objects are elementary building blocks. TOM's notion of objects is obviously inspired by Smalltalk, in that for every defined class, a class object, or factory object as it is sometimes called, exists. A class object describes the state (instance variables or member variables) and behaviour (instance methods or member functions) of its instances. Conceptually, each class object is the sole instance of its meta class object, the meta class object describing the state and behaviour of the class object. All meta class objects share the same meta-meta class object.

Classes and instances are distinct entities. A class of objects is only fully defined by both the definition of the class and the definition of the instances.

It is possible for instances not to carry any state; such instances can not actually be allocated, but their definition can be inherited by other objects, even class objects. A class with stateless instance is a behavioural class.

All classes with allocatable instances must inherit, directly or indirectly, from the State class: It is the State class that defines the instance and class variables necessary for the runtime system to function. Most notably, the State instance introduces the isa instance variable. For every instance, this variable points to the class object describing the instance.

A class or instance definition can declare methods to be deferred. A class having deferred methods, either because of its own definition or because of inheritance, is said to be a deferred class. Instances of a deferred class can not be allocated; only instances of a subclass which actually defines all deferred methods can be allocated.

A behavioural instance with only deferred methods (i.e. without providing any method implementation) resembles an Objective-C protocol, a Java interface, and a C++ signature. There are, however, elementary differences

A class can pose as another class. A posing class is inserted into the class hierarchy between the posed class and any subclass or client: all references to the posed class actually refer to the posing class (except for references from the posing class itself). Posing is especially useful in the context of library units over which the programmer has no source control.

With the semantics of extensions, posing might seem a bit too much like using a canon to shoot a mosquito. All posing really adds is the ability to override methods while still being able to refer to the original. The real advantage of posing is that referring to the original method implementation is as simple as messaging super.

Facts

Syntax

class_name:
          IDENTIFIER
        | unit_name `.' IDENTIFIER
        ;

A class name is either an identifier, or an identifier qualified by the name of the unit in which it is defined (see section Units for an explanation of units).

An unqualified class name must refer to the only class name visible or it is an error. A class Foo in some unit myprog makes classes by the same name, in units upon which the unit myprog depends, invisble.

The type of instances of a class is denoted as the class_name; Shifted in the direction of the class make it denote the class object.

/* my_foo references an instance of Foo
   or an instance of a subclass.  */
Foo my_foo;

/* foo_class references the Foo class
   or a subclass thereof.  */
class (Foo) foo_class;


Go to the first, previous, next, last section, table of contents.