Java - Calling all methods of a class
- by Thomas Eschemann
I'm currently working on an application that has to render several Freemarker templates. So far I have a Generator class that handles the rendering. The class looks more or less like this:
public class Generator {
public static void generate(…) {
renderTemplate1();
renderTemplate2();
renderTemplate3();
}
private static void render(…) {
// renders the template
}
private static void renderTemplate1() {
// Create config object for the rendering
// and calls render();
};
private static void renderTemplate1() {
// Create config object for the rendering
// and calls render();
};
…
}
This works, but it doesn't really feel right. What I would like to do is create a class that holds all the renderTemplate...() methods and then call them dynamically from my Generator class. This would make it cleaner and easier to extend. I was thinking about using something like reflection, but it doesn't really feel like a good solution either.
Any idea on how to implement this properly ?