This document describes other important features and mechanisms which are part of the language
or class library, but have been ignored until now.
Beside Globals, Method Locals and Instance Variables,
there are also:
- Class Instance Variables
Because classes are also objects, they too can have addition private variable slots,
much the same as normal objects can. A class instance variable's definition is inherited by
a subclass; however, the subclass may place its own value into its slot.
That means, once defined by a class, the class and all of its subclasses have that slot,
but each one may put a different value into it.
Class instance variables are seen by class methods only.
Their lifetime is the lifetime of the class.
- Class Variables (also called "Statics" in newer literature)
These are defined in the class definition template. Their lifetime is that of the class.
They are visible both from class- and from instance methods.
They are shared with and seen by subclasses.
This means, that in contrast to the above class instance variables,
subclasses do not have their own private slot. Instead, they all share the single variable
cell that the defining class created.
- Pool Dictionaries
Pool variables are seen by all classes which "subscribe" to a given pool.
Then all the variables defined by that pool become visible and accessable within a class on
both the class and instance side.
- Block Local Variables
Block locals are similar to method locals.
They are seen within the block.
This includes all containing sub-blocks.
Due to the closure-behavior of both block- and methodContexts,
these variables may outlife their defining blocks life.
This happens always, whenever a subblock which referres to such a variable
is exposed to somewhere outside the block. For example, when a subblock is stored into
a variable or another object, or if it is returned as a value.
Block/ and Methodvariables are stored in so called Contexts.
These are created for every method- or block invokation.
They have to major purposes:
- to remember the callers context and keep the current pc (for proper return to the caller)
- to store local variables (method- and block variables)
- to provide space for intermediate values (expression evaluation stack)
In other programming languages, these would be called Stack frame, and thats what they
are most of the time. However, via the pseudo variable thisContext,
they can be accessed at any time and treated like any other first class object:
you can store them in other objects or return them as value.
Continue in "More Smalltalk".
Copyright © Claus Gittinger Development & Consulting
Copyright © eXept Software AG
<cg@exept.de>
Doc $Revision: 1.2 $ $Date: 2012/02/13 11:57:26 $