Delphi idioms – helpers

As you can see, writing decorators can result in lots of very tedious work. If you check the DecoratedStream unit, you'll see more than 900 very boring lines. Is there a better way?

The answer to that is both yes and no. It's no if we want to stick to traditional decorator implementation, but it's yes if we are a bit more pragmatic than that and we use a Delphi-specific concept of helpers.

Delphi helpers give us a way to extend existing classes, records, and even simple data types with new methods. They work in the same open/closed way as decorators. The original class, record, or data type stays the same (is closed), but as far as the other parts of code are concerned, it is extended with the new functionality (is ...

Get Hands-On Design Patterns with Delphi now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.