Java - Calling all methods of a class
Posted
by
Thomas Eschemann
on Stack Overflow
See other posts from Stack Overflow
or by Thomas Eschemann
Published on 2014-06-11T09:21:36Z
Indexed on
2014/06/11
9:24 UTC
Read the original article
Hit count: 224
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 ?
© Stack Overflow or respective owner