11.3 GENERATOR OUTPUT PATTERNS
Generators produce a wide variety of different kinds of output: simple text,
documentation, .ini ?¬?les, XML, database de?¬?nitions, and of course various kinds of
code. For generation to be possible, the output required from a given generator over
different models must exhibit patterns. If there is nothing an expert human can
recognize as a pattern common to several examples of the kind of output you want,
there is no way to generate it. Fortunately, even a glance at the kind of code most of us
are forced to write these days shows there is plenty of scope for removing duplication.
276 GENERATOR DEFINITION
Even after removing duplication, a trained eye can spot many cases where textbook
patterns have been applied, particularly in well-written code.
In a similar way, there are patterns to use when writing generators. Some kinds of
tasks seem to crop up often inDSMgenerators, and knowing a good basic solution can
save signi?¬?cant time.
11.3.1 Simple Text
Simple text ?¬?les such as con?¬?guration ?¬?les or script ?¬?les are generally easy to
generate. They tend to fall into three categories:
(1) Largely boilerplate
(2) Con?¬?guration and settings ?¬?les
(3) Script ?¬?les
The easiest are of course ?¬?les that consist largely of boilerplate text, where the
majority of the text remains the same independent of the model contents.
Pages:
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511