Show in Frame No Frame
Up Previous Next Title Page Index Contents Search

6.7.3 Subgenerators and modularization

Subgenerators provide a useful mechanism for modularization of generator definitions. However, organizing and calling subgenerators can get fairly complex without a good generator hierarchy. A good technique to support generator hierarchies is to use the name of a type as the name for the generator definition related to that type. This enables you to call subgenerators using the type keyword to define the name of the executed subgenerator:
subreport type run
The obvious benefit of this approach is that it saves the metamodeler from writing multiple if clauses when deciding which subgenerator to run when there are several available. This solution is also extendable: if a new type becomes available as one choice among others, it can be handled just by adding a generator of the same name for it.

For practical examples of using subgenerators, please see the code generator for the Watch example. In general, it is good to use a prefix before the type name, e.g. to distinguish between different programming languages. This also allows the Generator Editor Hierarchy view to tell that the subreport call is to one of a limited number of generators, rather than apparently to any generator.
subreport '_Java_' type run

Show in Frame No Frame
Up Previous Next Title Page Index Contents Search