班级助手有什么好的用途? [英] What are good uses for class helpers?

查看:24
本文介绍了班级助手有什么好的用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Delphi(可能还有很多其他语言)有类助手.这些提供了一种向现有类添加额外方法的方法.无需创建子类.

Delphi (and probably a lot of other languages) has class helpers. These provide a way to add extra methods to an existing class. Without making a subclass.

那么,类助手有什么好的用途?

So, what are good uses for class helpers?

推荐答案

我正在使用它们:

  • To insert enumerators into VCL classes that don't implement them.
  • To enhance VCL classes.
  • To add methods to the TStrings class so I can use the same methods in my derived lists and in TStringList.

TGpStringListHelper = class helper for TStringList
public
  function  Last: string;
  function  Contains(const s: string): boolean;
  function  FetchObject(const s: string): TObject;
  procedure Sort;
  procedure Remove(const s: string);
end; { TGpStringListHelper }

  • 为了简化对记录字段和 删除强制转换.

    这篇关于班级助手有什么好的用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆