加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 提升后代类中方法可见性的最佳方法

发布时间:2020-12-15 09:36:12 所属栏目:大数据 来源:网络整理
导读:详细阐述这个问题的最好方法是举例说明我正在尝试做什么…… 我定义了一个“基类”: TMyBaseClass = class(TPersistent)protected procedure Foo(const AValue: String); virtual; // more methods here (many more in fact)end; 我现在定义一个后代类: TM
详细阐述这个问题的最好方法是举例说明我正在尝试做什么……

我定义了一个“基类”:

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

我现在定义一个后代类:

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

这里的问题是我必须重新定义TMyDescendantClass的方法“Foo”以将链调用传递给TMyBaseClass:

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

这是浪费空间!我想知道是否有人知道任何方式来否定重新实现该方法的需要并且“继承”.

一个理想的解决方案看起来像:

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

显然这是假设的,我知道Delphi语言中不存在关键字“已提升”.是否有一个关键字具有相同的效果,我只是不知道?

谢谢!

解决方法

没有这样的关键字.你可以轻松地 change the visibility of a property by redeclaring it with a new visibility level.但是没有类似的方法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读