Report generators - I need some smart design pattern ;)
so there a webapp (Seam + JSF/Facelets) that I'm working on right now and I need to create report generating service - currently three different report types and three different formats. I would like you to suggest some nice pattern do implement this feature, that could save me things in actionBean like:
if (selectedFormat == pdf) {
pdfReportService.generateReportNr1();
} else if (selectedFormat == csv) {
csvReportService.generateReportNr1();
} else if [...]
So I guess there would be ReportGenerator interface with methods for different kinds of reports, and ReportGenerator implementations for different format types. But how to combine all supported format implementation in one service so that it could be easily called from the action bean without any switching logic? Should I gather开发者_开发百科 them in some common service and expose a List getSupportedFormats() method? Gimme your ideas :)
I'd use the abstract factory pattern, i.e. provide a report generator (factory) for each supported format (like a map format->factory). Then choose the factory that supports the selected format.
精彩评论