Re: Inherited explained



"Anonymous" <nobody@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5d9d94db38b53a2ae975810da32894f1@xxxxxxxxxxxxxxxxxxxxxxxxx

I have been unable to understand the inherited clause for many years.
[...]
What inherited infers is basically this: Do what you would have
normally done if I had not taken control of the situation.

That seems a very odd way to describe it.

'Inherited' is a keyword normally applied to a method call - while
it is possible to use it by itself, that is merely a special case,
much like leaving 'Self.' off a method call. Your example with a
message handler is also a further special case because they hide
the appearance of virtual methods overrides.

You can call the inherited version of any other method besides the
current one, or evaluate an inherited property. The usual case,
however, is to call the previous version of the current method.

The modifier becomes useful when applied to a virtual method that
has been overridden in the current class. For such methods, it
specifies to not call the latest override of the method, but to
resolve the name in the immediate parent class instead[0]. (That's
really what it specifies everywhere, of course. And I'm not sure
about the exact implementation of message handlers, but conceptually
and probably practically, they are similar to method overrides.)

This is useful because in class-based object orientation, a class
is expected to inherited and extend the behaviour of its ancestor
classes. Without a way to incur the ancestor class's behaviour,
extension would be impossible. In Object Pascal, 'inherited' is
that way.

So, in a way, what you are saying is not exactly _wrong_. But
it carries a load of assumptions. You seem to be unaware of the
possibility to explicitly mention which method to call. Frankly,
I've never done otherwise, because I don't trust the compiler to
get the parameters right.

But far more worrying is your characterisation of what you are
doing as 'taking control of the situation', where in fact you are
merely building on existing code and behaviour. This suggests to
me that you have a very ad-hoc and antagonistic understanding of
how to build a system of cooperating classes. I think you would
do well to give your base classes more credit. It is normal to
have to override some behaviour here and there, but that is not
indicative of gross errors in existing classes; quite the contrary,
it means that you have recognised that there is much of value in
them that you _can_ re-use.

Or it may merely indicate that you didn't know that 'inherited'
is really about virtual methods and parent classes, and had only
seen it in relation to message handlers. Although in that case,
I would suggest that you have a very fragmented and ad-hoc
understanding of all of Delphi, and would do well to read a book
about it. The OPLG comes to mind; it also explains some more
general programming-related subjects.

You may note that I have inferred (the word being used correctly
this time) quite a lot of your state of mind from one simple turn
of phrase. I may be wrong. Please come back with further questions,
and a tart note of your own when called for.

Groetjes,
Maarten Wiltink

[0] This also means that if a method has not been overridden in the
current class, calling it as 'inherited' makes no difference.
The compiler will _not_ search upwards for the first different previous
version, it will just go up one level before seeing what the method
name means.


.



Relevant Pages

  • Weird behaviour overriding Text prooperty in user control
    ... I am trying to create a control by sub classing the ... Text property to "bar" and connect a button to the Foo ... Protected Overloads Overrides Sub Dispose(ByVal ...
    (microsoft.public.dotnet.general)
  • RE: Master Page Gridview Export Excel
    ... Public Overrides Sub VerifyRenderingInServerForm(ByVal control As ... a form tag with runat=server. ...
    (microsoft.public.dotnet.framework)
  • Re: Link dialog with existing c++ class in Visual Studio .net 2003
    ... > Everything ported correctly and runs in Visual Studio .net. ... > or modify message handlers from the dialog view. ... >> overrides, you will have to do some additional work. ... >> All commented text is used by VS class wizard to parse and insert ...
    (microsoft.public.vc.mfc)
  • Re: Cant seem to add XmlIgnore override on inherited property
    ... attribute overrides. ... Your type MyControl has no member by the name Site. ... base type of Control. ... > not being able to serialize the Site property. ...
    (microsoft.public.dotnet.xml)
  • Re: When to redraw control?
    ... The OnPaintBackground and OnPaint overrides should be called automatically ... ControlStyles.ResizeRedraw enum value to have your control repainted when it ... I know that I need to redraw control when it's resized by overriding ...
    (microsoft.public.dotnet.languages.csharp)