Next: Sending messages
Up: Message Passing Pattern
Previous: Components of a constructor
Contents
Creating instances of a class
The diagram below illustrates what happens, when a constructor is invoked to create
an instance of a class.
The rectangles in the diagrams represent environment frames. Environment frames are linked
with one another making up (together with the global environent) the total environment.
The label `environment 1' refers to the inherited environment and `environment 2' to the
new environment frame created by the activation of a closure (call of a function).
In our example `environment 2' has been created by calling the constructor `make-account'.
- The first environment frame created in our example represents the top level environment
containing the constructor `make-account'
and the variable `acc1' used later on to store the object returned by `make-account'. An arrow pointing
from the second rectangle back to this environment frame symbolizes the linkage.
- The second environment frame belongs to the constructor containing its attributes (balance)
and methods (get-balance, deposit, self).
There are two closures of special interest in our example illustrated by the black bullets:
- the constructor
taking one argument: `balance' and having three methods. There is a
line drawn from this closure (two bullets) to the second environment labelled `environment 2'.
This line is to be interpretet as a pointer to the closure's activation record.
- the lambda-abstraction `self'
representing the object returned expecting
1 argument: `msg'. This closure has not been invoked yet and therefore has only the
inherited environment consisting of the environment frames already discussed.
Next: Sending messages
Up: Message Passing Pattern
Previous: Components of a constructor
Contents
Georg P. Loczewski
2004-03-05