I have the following base interface:
public interface Value{
double getValue();
}
I would like to have a few different Outputter interfaces that would take a Collection and output them, based on the CONCRETE type of the Value, so I could have a Value class that would have 10 other important fields, which should also be output. I know this falls nicely into a Visitor pattern, but my concern is this: Each outputter would always get a list of ONE specific type of Value, SO I could, in theory, supply a typed list of MeanValue, StdDevValue etc. I am not sure how to design this nicely, as Values are generated by another interface, so in fact, I am only holding a reference to Collection, and I do not want to downcast it and then call specific method on the Outputter…
The Visitor pattern doesn’t involve any casting. That’s the point of it.
Here’s the core of a Visitorised family of values:
Here’s the output bit:
You can use an
Outputterwith either a collection of mixed values, or a collection of a specific kind: