R
Rhino
I have a batch program that generates several flat files. The files being
generated are of various types, including HTML, ASCII, CSS, and PDF.
At the moment, each distinct file is generated in its own separate method.
The main of the class simply executes each method in turn. The different
methods share a small amount of data via class variables.
Is that a reasonable design from an OO point of view? Or should I create a
separate class to generate each file, with an interface to share data
between the different classes? If I go with separate classes for each file:
- would it be reasonable to do all the work of writing the file in the
constructor of that class?
- would it be reasonable to create a class called FileGenerator that simply
creates each file by invoking each classes constructor?
For instance, I can picture something like this:
public class FileGenerator implements GeneratorConstants {
public static void main(String[] args) {
new FileGenerator();
}
public FileGenerator() {
new File1(); //generate HTML file
new File2(); //generate ASCII file
new File3(); //generate PDF file
}
}
This approach is certainly nice and modular but is it good OO design?
Also, what about shared resources? Some of the files access the same
ResourceBundle to display the same data but in different file formats. For
example, the code that generates File1 reads from the resource bundle and
writes the information out in HTML format while File2 writes the same
information in ASCII, etc. Should FileGenerator get the desired
ResourceBundle and then pass it to the classes that need it via their
constructors? Or would it be better OO design to let each class get its own
ResourceBundle directly?
I've never had much exposure to OO design of any kind and even less to
design of batch programs so I'm really not sure how to think of these
things. Maybe my current design where all of the files are being generated
via separate methods in the same class is perfectly good; I just don't know.
If anyone could enlighten me, I'd appreciate it.
generated are of various types, including HTML, ASCII, CSS, and PDF.
At the moment, each distinct file is generated in its own separate method.
The main of the class simply executes each method in turn. The different
methods share a small amount of data via class variables.
Is that a reasonable design from an OO point of view? Or should I create a
separate class to generate each file, with an interface to share data
between the different classes? If I go with separate classes for each file:
- would it be reasonable to do all the work of writing the file in the
constructor of that class?
- would it be reasonable to create a class called FileGenerator that simply
creates each file by invoking each classes constructor?
For instance, I can picture something like this:
public class FileGenerator implements GeneratorConstants {
public static void main(String[] args) {
new FileGenerator();
}
public FileGenerator() {
new File1(); //generate HTML file
new File2(); //generate ASCII file
new File3(); //generate PDF file
}
}
This approach is certainly nice and modular but is it good OO design?
Also, what about shared resources? Some of the files access the same
ResourceBundle to display the same data but in different file formats. For
example, the code that generates File1 reads from the resource bundle and
writes the information out in HTML format while File2 writes the same
information in ASCII, etc. Should FileGenerator get the desired
ResourceBundle and then pass it to the classes that need it via their
constructors? Or would it be better OO design to let each class get its own
ResourceBundle directly?
I've never had much exposure to OO design of any kind and even less to
design of batch programs so I'm really not sure how to think of these
things. Maybe my current design where all of the files are being generated
via separate methods in the same class is perfectly good; I just don't know.
If anyone could enlighten me, I'd appreciate it.