Waldek Hebisch wrote:
Peter N Lewis wrote:
[snip]
For Mac Pascal, you can never entirely remove a parent method, and you can all the parent method from within the method by calling "inherited p" (but that is only allowed in an overriden method p).
Do you mean that the following is illegal?:
type a = object procedure p; end; b = object(a) procedure q; end;
procedure a.p; begin end;
procedure b.q; begin inherited p end;
I'm not exactly sure what Peter is referring to here, but your exmple should be legal in a complete program.
A better example program to demonstrate the working of "inherited" in MacPascal:
program InheritedTest(output);
type a = object procedure p; end; b = object(a) procedure q; procedure r; end; c = object(b) procedure p; override; end;
var cInstance : c;
procedure a.p; begin writeln('in a.p') end;
procedure b.q; begin writeln('in b.q'); inherited p end;
procedure b.r; begin writeln('in b.r'); p end;
procedure c.p; begin writeln('in c.p'); end;
begin new(cInstance); cInstance.q; cInstance.r; dispose(cInstance) end.
The output is:
in b.q in a.p in b.r in c.p
From this, you should be able to see "inherited" added to a method call
is used to specify calling a method in the declared (immediate) parent of the declared object type. The method doesn't have to be explicitly declared as a new method or overridden method in the direct ancestor parent - the method just has to be declared somewhere in the ancestory type chain. If there is more than one method in the ancestory chain (i.e., one or more method overrides), the first method encountered as you traverse the type chain from immediate parent to the root of the chain is the one called.
Without "inherited", the implicit "self" is used to to make a virtually dispatched method call; self.p in this example. The method actually called is the one associated with the object type of self at the time of the call.
An additional point that might need some clarification is on what "override" is classified as in MacPascal. Peter, in one or two previous postings, has used "keyword" to classify "override". As most people think of "keyword", that really isn't correct for "override". Technically, in MacPascal, "override" is classified as a Pascal language directive; therefore, it only has specific language significant meaning in the directive "slot" of a method heading declaration. For example; you could put the following declaration:
var override: integer;
immediately after the program heading in the above program, and the program is still a legal MacPascal program.
Gale Paeper gpaeper@empirenet.com