I have the following situation. I have a factory method that returns a matrix. This matrix can be calculated at two levels of accuracy: level1 and level2. In order to calculate the matrix, I need to pass a bunch of information to the factory method, and this information is nicely packed in another object Info. Info is passed to the factory method, and the matrix is returned.
Info contains details that are needed for both levels of accuracy. a set of these details are used only by level1. If level2 is needed, info must contain additional data which are used to evaluate level2 accuracy.
I have two strategies to perform the decision:
- I pass the Info object to the factory method. If it finds the info for level2, it computes level2 accuracy. If it finds only info for level1, it computes level1.
- you pass the factory method both the Info data and the requested accuracy level, then use only the Info contents useful for the appropriate level. There may be a case where level2 is requested, but Info does not contain any level2 information. In that case the program will throw an exception.
Which option would you consider better ?