What is a design pattern?
While several definitions can be formulated, they all contain one universal message. In my opinion the most accurate definition is given in the Wikipedia:
I would like to draw your attention to two lines:
- general reusable solution
- solve common problems
Let's consider whether developing application in RAD style (visually), can we use general reusable solution and do we solve common problems? Of course, every day. Developers in Delphi are using design patterns, even if they do not realize it.
Delphi UI patterns
Some of this patterns are related to user interface and much less is VCL agnostic. UI patterns in VCL are well known and often without using them it’s difficult to build working solution. I can list here a few of these patterns: forms inheritance, form separation using frames, grid centric UI, master-detail layout with edits and navigator for the master and grid for the details, non-editable grid with item list and modal form with editable controls, and much more.
Visual patterns are popular among Delphi developers, but I do not know anyone who would dare to public and named them. Several books describe how to apply elements, but they do not treat them as reusable patterns. In practice each group of developers builds and discovers them internally. Sometimes this discovery takes many years. In my opinion, this is excellent material for a new book on developing UI in Delphi.
Non-visual Delphi patterns
Looking for these non-visual patterns I found only four, for sure there are a bit more but not so much. All this patterns are very useful, but they also have their dark side of the force. During designing them, the highest priority was the simplicity of use and not the maintenance. For this reason, they work great in small projects, and as these projects are growing they are becoming less and less comfortable. This four pattern non-visual pattern suggestion are: Data set pattern, Action pattern, Data module pattern, Delphi event pattern. Certainly some I missed so please comment below.
Data set pattern
It's not just about the TDataSet component and their descendants, but about general architecture and his behavior, I mean: tabular structure with strongly typed columns, with access to one data row, with state (e.g. browse, edit, insert), with TField collection containing visual metadata and internal integrity metadata, with events used for notifying other application areas, with internal datatalink, and external TDataSource component, and much more.
During my consultancy work I noticed that most Delphi developers learned by trial-and-error method how to apply this pattern, but only some of them are able to use full power of this pattern in a sensible way. Some developers have learned that data set can be useful not only in database applications, but can be used in any application that contains data. Thanks to the ability to create dynamically memory data sets and visualize them in any way.
Well-used pattern becomes a very powerful tool in the hands of the architect. Full use of a field metadata allow to build dynamic and flexible solutions. As an example, I would like to write about methods converting data from a TDataSet object to a JSON / XML collection, or automatically generate tabular report template and many other data transformations.