Should Class Helpers be used in developing new code?

前端 未结 10 1878
眼角桃花
眼角桃花 2021-02-14 10:51

Delphi 8 introduced Class Helpers for the purposes of mapping the VCL/RTL to the .NET object hierarchy. They allow injecting methods into an existing class without overriding t

10条回答
  •  萌比男神i
    2021-02-14 11:19

    Maybe a good aproach you can use is (as I use it):

    1. Always give preference to inheritance over class helpers, use them only when inheritance is not an option.
    2. Give preference to Class helpers over bare global methods.
    3. If you're going to need the extendend functionality in more than a Unit, try something else (like class wrappers).

    .Net Extensions methods are way too similar and where created and supported for the exactly same reason: Make an Extention of the base classes (rather than an upgrade wich in Delphi.Net was not an option in order to try to make Delphi native code kind of "compatible" with .Net code - IMHO this was too ambitious)

    Anyway, Delphi Class helpers are still quite a tool in some situations.

提交回复
热议问题