Revised: Re: Inherited explained
- From: "Rudy Velthuis" <newsgroups@xxxxxxxxxxxx>
- Date: Wed, 22 Oct 2008 00:47:09 +0200
Anonymous Remailer wrote:
With all due respect, your knowledge into delphi/pascal has created
a completely incoherent explanation.
Then start with a simple tutorial. He used terms one ought to know.
This is why I have not been
able to completely comprehend the inherited statement before.
I will protest this line, however: 'This suggests to me that you
have a very ad-hoc and antagonistic understanding of how to build a
system of cooperating classes.'
To go into slandering someone's character in your explanation is
patently wrong.
No, it is a realistic assessment. Someone who does not understand what
inherited means can only have such an ad hoc understanding of classes.
So what you should probably do is start from the beginning, with a
simple tutorial about object oriented programming, if possible about
Delphi. It can't hurt, and even seasoned programmers should, IMO,
sometimes do that.
But just in case you come from a different language: In a method,
inherited calls a function in the base class, it is like .NET's
base.somecall(), which also calls the function somecall() in the direct
ancestor of the current class in the inheritance hierarchy.
Inherited without a function name will call the method of the same name
as the current one, with the same parameters, in the direct ancestor
class. The difference with a call to inherited with a function name is
that if there is no method to be called in the direct ancestor, it will
simply be ignored.
Example:
type
Base = class
...
procedure DoSomething(I: Integer); virtual;
...
end;
Derived = class(Base)
...
procedure DoSomething(I: Integer); override;
procedure SomethingElse(C: Char);
...
end;
procedure Base.DoSomething(I: Integer);
begin
Writeln('Do something in Base');
end;
procedure Derived.DoSomething(I: Integer);
begin
inherited; // calls Base.DoSomething(I);
Writeln('Do something in Derived');
end;
procedure Derived.SomethingElse(C: Char);
begin
inherited; // does nothing, since there is no Base.SomethingElse
inherited SomethingElse(C);
// error, since there is no Base.SomethingElse
end;
--
Rudy Velthuis http://rvelthuis.de
"After every 'victory' you have more enemies."
-- Jeanette Winterson
.
- References:
- Re: Inherited explained
- From: Maarten Wiltink
- Re: Inherited explained
- From: Anonymous Remailer
- Re: Inherited explained
- Prev by Date: Re: Inherited explained
- Next by Date: Re: Inherited explained
- Previous by thread: Re: Inherited explained
- Next by thread: Re: Inherited explained
- Index(es):