When you define a class, you have to specify a parent class. So how do
you start defining classes? There is one class available from the start:
object
. You have to use it as ancestor for all classes. It is the
only class that has no parent. Classes are also objects, except that
they don’t have instance variables; class manipulation such as
inheritance or changing definitions of a class is handled through
selectors of the class object
.
object
provides a number of selectors:
class
for subclassing, definitions
to add definitions
later on, and class?
to get type informations (is the class a
subclass of the class passed on the stack?).
object-class
( "name" – ) oof “object-class”
object-definitions
( – ) oof “object-definitions”
object-class?
( o – flag ) oof “class-query”
init
and dispose
as constructor and destructor of the
object. init
is invocated after the object’s memory is allocated,
while dispose
also handles deallocation. Thus if you redefine
dispose
, you have to call the parent’s dispose with super
dispose
, too.
object-init
( ... – ) oof “object-init”
object-dispose
( – ) oof “object-dispose”
new
, new[]
, :
, ptr
, asptr
, and
[]
to create named and unnamed objects and object arrays or
object pointers.
object-new
( – o ) oof “object-new”
object-new[]
( n – o ) oof “new-array”
object-:
( "name" – ) oof “define”
object-ptr
( "name" – ) oof “object-ptr”
object-asptr
( o "name" – ) oof “object-asptr”
object-[]
( n "name" – ) oof “array”
::
and super
for explicit scoping. You should use explicit
scoping only for super classes or classes with the same set of instance
variables. Explicitly-scoped selectors use early binding.
object-::
( "name" – ) oof “scope”
object-super
( "name" – ) oof “object-super”
self
to get the address of the object
object-self
( – o ) oof “object-self”
bind
, bound
, link
, and is
to assign object
pointers and instance defers.
object-bind
( o "name" – ) oof “object-bind”
object-bound
( class addr "name" – ) oof “object-bound”
object-link
( "name" – class addr ) oof “object-link”
object-is
( xt "name" – ) oof “object-is”
'
to obtain selector tokens, send
to invocate selectors
form the stack, and postpone
to generate selector invocation code.
object-'
( "name" – xt ) oof “tick”
object-postpone
( "name" – ) oof “object-postpone”
with
and endwith
to select the active object from the
stack, and enable its scope. Using with
and endwith
also allows you to create code using selector postpone
without being
trapped by the state-smart objects.
object-with
( o – ) oof “object-with”
object-endwith
( – ) oof “object-endwith”