Template-based
or strict model visitor generators may well require some extra work or hacks to
produce the required output, as noted above.
11.4.4 Generator per Object Type
When generating from a single model, the form of the output required normally varies
according to the type of the object in question. This is the basis of the model visitor
pattern, which says that each object type should have its own generator. Where the
strict model visitor implementations fall down is when information from the same
object is required in several different places in different forms. This is no problem
for other generators, but they would still do well to make a clear connection between
the object type and the generators for it.
In most non-API generators, object types themselves do not have their own
generators. Instead, the generators are stored globally or with each modeling
language. In this case, the subgenerators for each object type can be named after the
object type. Where the object type requires different output for different parts of
the generation, the names can be formed by pre?¬?xing the kind of output required to the
name of the object type, for example, Action_Alarm and Action_Icon for the Alarm
and Icon types??™ actions in the Watch example.
This order is generally better than the reverse order??”which would be more
familiar from object-oriented programming??”because there tend to be more
similarities between all of the Action generators than all of the Alarm generators.
Pages:
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563