I have a simple (and possibly quite common) design issue. Let's say I have an interface that looks like this:
public interface AnalysisResult {
BigDecimal getMeasure();
}
This, However, is later implemented by several different concrete implementations - some including average field as well, some containing counts of various properties etc. Now, I am given a set of AnalysisResult
and I would like to be able to output the results according to the type, i.e. Mean result would say what the mean is on top of the Measure etc. One way to do this would be to expose a method on the interface say outputResult()
, but the problem is I might want to output the result in the HTML format, CSV and many others, so I would require a method for each. Also, there might be the case I want to output something based on the type, such as : 'This is the Mean result'... Would you say that in this case it would be easier to simply use instanceof
and do the work on the outputter side?