In my application, several different reports can be generated (CSV, HTML, etc).
Instead of creating a traditional factory-style method pattern, I was planning on adding a method to the body of enum constants that would create and return the appropriate report object.
public enum ReportType {
CSV {
@Override
public Report create() {
return new CSVReport();
}
},
HTML {
@Override
public Report create() {
return new HTMLReport();
}
};
public abstract Report create();
}
With a specified ReportType enum constant, I could then easily create a new report by executing a statement like the following:
ReportType.CSV.create()
I wanted to get the opinion of others on using this approach. What do you think of this? Would you prefer any other approach, and if so, why?
Thanks