When you have the working code, use that as a basis for the generator. Actually, the
working code itself is your ?¬?rst generator: simply make the generator consist of one
304 GENERATOR DEFINITION
large literal string! While that generator will produce exactly the right output for this
model, we want to progressively break down that generator into smaller elements,
with conditionals, loops, and reading values from the model. Follow the four steps of
Section 11.1 to gradually reduce the generator down to its minimal form. You can run
the generator and diff the output with the original handwritten code to check your
progress.
Remember to keep the generator as simple as possible: push decisions and
complexity down into the generated code (and later into the domain framework). If the
generator needs more information, identify the extra problem domain knowledge that
needs to be captured by the modeling language and ?¬?nd a minimal natural
representation for it.
Once you have a working generator for that example model, take a snapshot of the
model, generator, and code. Then try changing things in the model, and make sure the
code still works but re?¬‚ects the change. You can test both by running the code and by
comparing the code with the snapshot. Start with simple changes like names that will
be visible in the running application, and progress to more complex ones like adding
an extra object.
Pages:
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571