Consider code generators
Some types of classes share the same basic structure, and differ only in details. Type-safe enumerations (at least in JDK 1.4) and data-centric Model Objects are two examples. In such cases, aids for rapid code generation become very useful. These may take several forms :
- a simple template of text intended for copy-and-paste
- a passive code generator - generates source files which may need further edits. If further edits are performed, then they will be lost if the code generator is run a second time.
- an active code generator - generates source files which will not need further edits (the idea here is to use the code generator as part of the actual build, instead of relying on it for a one-time operation)
- a round-trip code generator - generates source files which may need further edits. If further edits are performed, then they will not be lost if the code generator is run a second time, since it will detect such edits, and use them to update its internal model.
The extensive use of code generation is often called Model-Driven Development
(MDD), or Model-Driven Architecture (MDA).
Would you use this technique?
|
|