Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: typos

...

No Format
group Java;
method(name,code) ::= <<
public void <name>() {
    <code>
}
>>

Suppose that you want also want the option for the method template to be able to optionally generate place debugging statements into the generated method code that includes debugging statements. (To be clear about this example: this would be debugging code to debug in the generated Java method, not code to debug the template processing itself.)

You could employ conditionally included subtemplates (using start placing debug text into the existing template, making it optional using the conditionally-included subtemplates feature, placing <if(...)> etc)  etc  around the debugging lines, but . But that clutters up the templates of the Java group considerably, and also fails to achieve proper separation of concerns.

Instead you would like to have all debugging stuff encapsulated in a separate template group which focuses on debugging. In that template group, you could create an overriding template for method template by copying and pasting the entire existing method template and inserting your additions. But then you are duplicating all of that output literal text, which breaks the "single point of change principle."

Instead just leave a hole in the main method template that a subgroup can override, here a location marked with <@preamble()>:

...

(To be clear about this example, here the ths template's purpose is to produce "if" statements in the output language, here Java. That "if" is unrelated to the issue of using template <if(...)> expressions, which we are discussing how to avoid.)

...