课堂助手有什么好用处? [英] What are good uses for class helpers?

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

问题描述

德尔福(可能还有很多其他语言)有类助手。这些提供了一种向现有类添加额外方法的方法。



那么,类帮助器有什么好用?

解决方案

div>

我正在使用它们:




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?

解决方案

I'm using them:

  • 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 }
    

  • To simplify access to record fields and remove casting.

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

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