refactor: use NVI idiom for Start, Run, and Stop functions
#434
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adopt the Non-Virtual Interface (NVI) idiom for algorithms'
Start,Run, andStopfunctions.Before this PR
Base-class
Algorithmhas 3 pure virtual functions:Subclass algorithms (i.e., the algorithms themselves) must override and implement:
After this PR
AlgorithmfunctionsStart,Run, andStopare nowfinal, so they cannot be overridden; they are meant to staypublicfor the user and should not be changed by subclassesprivatevirtual functions, called "hooks", which may be overridden by subclass algorithms; they are called by thepublicfunctionsThe implementations of the
publicfunctions are in the base-class'sAlgorithm.cc, and they call newprivatehook functions; basically:Required changes in Algorithms
In subclass algorithms (i.e., the algorithms themselves), 2 changes are required:
Algorithm.hpublicoverride function declarations ofStart,Run, andStopwithprivatedeclarations of the hook functions that will be usedprivateAlgorithm.cc:Start) toConfigHookParseYAMLConfigcallsStart->StartHookRun->RunHookStop->StopHook(or just remove it entirely if it's not used)Analogous changes are required in validators.
See this PR's
difffor examples of the required changes, since this PR updates all existing algorithms and validators.Purpose
Moving to the NVI pattern lets us:
Start,Run, andStopfunctions such that it applies to all algorithms and validators; I've already used this to load configuration parameters for all algorithms (fixing setting log level from custom YAML file will not work for algorithms with no configuration #351)