If you have any more information about call-by-number I
would be curious to
see it. Sounds a little like paint-by-
number for programmers.
In an
object-oriented language, the methods associated with
a class are fixed, but a
given call in the source program
will be dynamically dispatched at execution
time to the
method of that name for the actual object passed as
the
controlling parameter.* This dispatching is done using
a dispatch table
listing the methods for the object.
Due to class derivation, these methods
have to start with
the primitives of the ultimate parent class (object
in Java) followed by the additional methods in class order
from parent to
child. Note that if a method is overridden,
the overriding method gets put in
the dispatch table in
place of the method it overrides. The overriding
declaration need not be visible at the point of the call,
but it must have the
same parameter and result profile as
the declaration of the method it
overrides.
So yes, each method has a number, which can be computed by a
compiler, and stuck in the generated code. What can't
always be determined at
compile time is whether the class of
the controlling parameter at the point of
the (execution
time) calls will have a method corresponding to that number.
If the number is low enough, no check is needed, otherwise a
check is needed
and an exception may occur.
*Ada in particular allows the controlling
class to be
determined by the function return specific type instead.
This is
nice when creating constructors, but a minor detail
here. [ Reply to This | Parent | # ]
|