Re: Inheritance in Moto
David Hakim <dhakim-Gkm/TONP9n1Wk0Htik3J/[email protected]> Sat, 25 Jan 2003 16:37:51 -0500
| Newsgroups | gmane.comp.lang.moto.devel |
|---|---|
| Message-ID | <[email protected]> |
On Saturday, January 25, 2003, at 05:14 PM, Stefano Corsi wrote:
> For inherited classes, do you think is better to copy the parent
> methods and
> members definition in the new class definition or to have the various
> interface functions perform recursively on the parent chain to find
> the right
> method and/or member?
>
> Stefano
Hmm, I haven't thought too much about this.
For the interpreter either way should be fine although if you copy
methods into the new class definitions you will probably have to add
some nasty checks when someone overloads a method in a child class so
that a 'method redefinition error' doesn't occur. Also, in the compiler
you will have to make sure the parent method definition is only written
out once . Sooo after thinking about it I guess a recursive function
that discovers the nearest ancestor that defines the method is the way
to go
With regard to compiled code we want to avoid any non-fixed-cost
operations. What I had in mind for this was the pre-computed function
pointer array in the Class objects I mentioned in a previous email e.g.
If
A defined methods a(),b(), and c()
B extends A and defines its own b()
C extends B and defines its own c() and d()
then the class definitions for the above three classes would have a
pre-computed array of function pointers that look like:
A Definition Methods { A::a, A::b, A::c }
B Definition Methods { A::a, B::b, A::c }
C Definition Methods { A::a, B::b, C::c, C::d }
Does this help ?
-Dave