The goal of this article is to set up a methodology anyone can use to define patterns. A previous knowledge and experience on Patterns (GX 9.0) is necessary.
First: write a description of the pattern#
Writing your own pattern is a far more complex task than using an existing one, so the first step before writing anything is to check the Business Patterns Catalog to see if it already exist!
Assuming there's nothing similar, write the description of the pattern and put it in the Business Patterns Catalog. Follow the Pattern Description Guidelines.
Martin Fowler has a good essay on the subject named Writing Software Patterns.
Second: program the canonical example#
Go to GX and develop the canonical example. Show it to as many people as possible in order to get valuable feedback.
Some things to take in count:
- When developing the sample, always take in count in what other areas the pattern will be applied.
- Try to program in as easy to generate as possible way, for example use &Var.ToString() instead of DTOC(&Var) (the first one doesn't depend on the variable's type).
- Use as many components as possible. This way less code is needed to be generated, simplifying writing the templates and making the pattern more easy to upgrade.
Third: define the instance file and configuration file#
Once you have the sample, it is necessary to 'generalize' it. In other words it's necesary to define which will be the parameters of the pattern.
There are two types of such parameters:
- Instance parameters. They are the parameters the user will set in the Pattern Instance File.
- General parameters. They are parameters that apply to all instance files (ex: common text, location of gxchart, etc.). This parameters are defined in the <PatternName>.config file.
In summary this task consist on defining the structure of the Instance and Config files. To do it isn't required many tech skills, just basic knowledge of XML and of course a deep knowledge of the pattern being developed.
It also worth to define the default values of these files in order to facilitate the Fifth Step.
See Pattern Specification for more details.
Fourth: write the template files#
This is the most techy part!.
See Pattern Template Syntax and Using the Visual Studio Template Editor.
Fifth: write instance file default code#
It's very user friendly to start a new instance file with most of the values already in place. This is also a techy part, which most of the time needs to read the KB (using the DLLs provided by the pattern tool) to fill the instance file.
Sixth: use it!#
Patterns detailed operation
See Make Your Own Patterns Using GXPatterns for presentation on this subject.
Desarrollo de Patterns (1) and Desarrollo de Patterns (2) (in spanish).