Class Helpers: Extending Classes for Context

NEWSFLASH: I believe I have found a use for class helpers in the wild! This, even though I have long held the view that class helpers should not be viewed as a general purpose utility. They were designed for a very specific purpose and the authors of the technology themselves tell us how they are intended to be used. Using them in other ways is asking for trouble: they can break your – or others – code, they hide details of an implementation in A Bad Way™ and you are likely to run into limitations because what you want to use them for doesn’t tally with what they are intended to be used for. But, somewhat to my surprise, I have recently found what I consider to be a legitimate use for them. Less surprisingly, it actually fits with their intended use.

Class Helpers – Ruling from the Appellate Court

My previous post on class helpers provoked a passionate response from some quarters who believed that they could be used “safely”.  More worrying was an apparent belief that their use was actually endorsed by CodeGear – tacitly or otherwise.  A rather odd view given the advice from CodeGear themselves is to not use them. No-one actually described a safe usage scenario though and those scenarios that were described all contained immediately apparent flaws of their own.  However, I have realised that there is, if not a safe way then at least a responsible one, to create class helpers. Using them is still not entirely safe however.

Class Helpers On Trial

Class helpers (introduced in Delphi 2007 2006 2005 – thanks to Chris and Bruce for the corrections) seem to be cropping up more and more frequently in suggested work-arounds or implementation approaches.  I find this worrying given that this language feature has always come with the admonition from CodeGear that it isn’t advisable to use it! So why do people seem so keen on using them, and why shouldn’t they?