Posted 16 years ago on 2/7/2009 and updated 9/20/2009
Take Away:
A. In Dephi, class helpers allow you to extend a class without using inheritance. With a class helper, you do not have to create and use a new class descending from a class but instead you enhance the class directly and continue using it as you always have (even just with the DCU).
B. In general terms, developers sometimes use the term to refer to any class that helps out another class.
A. In Dephi, class helpers allow you to extend a class without using inheritance. With a class helper, you do not have to create and use a new class descending from a class but instead you enhance the class directly and continue using it as you always have (even just with the DCU).
B. In general terms, developers sometimes use the term to refer to any class that helps out another class.
Class Helpers Help with Source Code Control
Like partial classes, Delphi class helpers are primarily a source code control feature. A class helper tells the compiler to increase the compile scope when resolving identifiers. A partial class is a class that can be split into two or more source code files and/or two or more locations within the same source file. In very general terms, class helpers allow you to easily extend a class when inheritance isn't possible or practical. Contrast with partial classes which are used for source code management with code generators and large classes to split ownership of a class. Class helpers allow you to cheat a bit while partial classes allow you to divide and conquer.
Delphi class helpers are especially usefull with code libraries such as the VCL where it is difficult to predict and implement all future uses. When designing a rich code library, you have to decide when to surface what functionality, which classes a user can inherit from, when to seal a class, etc. Sometimes, allowing a user to use class helpers to add their routines to your code library is the best approach. Whether you use them within you're own code is a bit more questionable but ultimately if the final code is more maintainable and easier to extend, then you've done your job.