Best approach to increasing the visibility of a method in a descendant class

The best way to clarify the question is to give an example of what I'm trying to do ...

I define a "base class":

TMyBaseClass = class(TPersistent)
protected
  procedure Foo(const AValue: String); virtual;
  // more methods here (many more in fact)
end;

Now I define the descendant class:

TMyDescendantClass = class(TMyBaseClass)
public
  procedure Foo(const AValue: String); override;
  // etc. for all desired methods I wish to elevate into Public
end;

The problem here is that I need to override the "Foo" method for TMyDescendantClass to pass the call to the chain in TMyBaseClass:

procedure TMyDescendantClass.Foo(const AValue: String);
begin
  inherited;
end;

This is a waste of space! I am wondering if anyone knows of any way to deny the need to override the method and the "inherited" acll.

An ideal solution would look something like this:

TMyDescendantClass = class(TMyBaseClass)
public
  procedure Foo(const AValue: String); elevated;
  // etc. for all desired methods
end;

Obviously, this is hypothetical, and I know that the keyword “elevated” does not exist in Delphi. Is there a keyword with the same effect that I just don’t know about?

Thank!

+4
source share
2

. , . .

+6

?

, :

TMyDescendantClass = class(TMyBaseClass);

, :

TMyDescendentClass(myObject).Foo;

, :

TMyBaseClass = class(UnitName.TMyBaseClass);

:

myObject.Foo;
+3

All Articles