What is the answer to the question at the end of the previous post:
Is using an enum for analyzer family a good way to customize the processing in the client application (CT)
Well the answer in the case of our projet was no.
The stable part of the application ecosystem was the CT and the analysis cycle step in it. Adding an enum that we would then use to skip step in the processing would have made it impossible for us to add new Analyzer class without opening the code of the CT to support the new class.(remember the OCP or Open Close Principle)
What is an API designer to do in such a case ? Well, what we did was define an interface for the steps in the analysis cycle of the CT and implement a kind of
Decorator for that in all SM(I) instances. Of course, concrete instances of this interface are provided by the
IInstrumentDefinition factory. The main interface for this is something like:
interface IAnalysisSteps
{
void doStep (String stepName);
}
The CT supplies a default implementation of this that is in fact a supertype that looks like this:
interface IAnalysisStepHandler extends IAnalysisStep
{
void skipStep (String stepName);
}
The IInstrumentDefinition interface has a factory method that looks like:
IAnalysisStep getAnalysisStep (IAnalysisStepHandler analysisStepHandler);
The SM(I) implements a version of
IAnalysisSteps that will do one of two thing when it gets called:
- Simply call the default implementation of the
IAnalysisStepHandler
- Call the
skipStep(String) version of the method in the
IAnalysisStepHandler
Now SM(I) instances can customize the steps in the CT without actually having to open the code of the CT. What if new analysis steps are added to the CT ? Well, in that case you don't have any choice but to open the CT and to support that you simply have to implement the SM(I)
IAnalysisSteps decorator such that if an analysis step is unknown it is skipped. Since this step was originally not present in the CT skipping it should be a good default behavior for old SM(I) instances. I left out some details above like having different parameters for different analysis steps. That however is easily handled using a single additional parameter of type
Map<INamedParameter>. If you don't remember what a
INamedParameter is simply look at the previous blog entry.