I'm looking for the best design to apply to a situation with multiple DataObject
s and multiple output formats (ReportGenerator
s).
The current setup is something like this: there's a Formattable
interface that has various methods used by a ReportGenerator
. Each DataObject
(DataObject
could be any of several different unrelated classes) implements Formattable
-- ie, it knows how to organize its particular data for the report, and the ReportGenerator
is simply fed Formattable
objects from which it accesses String arrays and pretties them up.
1) So here is my first question: is this advisable? Because the result is that the process of organizing data for the report is strewn throughout all the DataObject
s. The alternative is an intermediary class with a whole bunch of instanceof
checks on what kind of DataObject
to format, but at least then it's all in one place.
2) And then my new problem is that I need to introduce a secondary ReportGenerator
which will need DataObject
data organized slightly differently. In the current setup, I could introduce a parameter on Formattable
methods to specify what kind of ReportGenerator
the DataObject
should format itself for, but again, not sure if this is advisable.
Aucun commentaire:
Enregistrer un commentaire