I'll describe what I'm trying to do, and hopefully, somebody can tell me what design pattern this is or point out a better alternative.
I have a method doing a bunch of complicated stuff that involves an approximation. It is possible to compute the result without the approximation but this involves more work.
What I want to do is get out some comparisons related to the inner workings of the implementation. My idea is to pass in an object that would do this extra work and store the info about the comparisons.
I think I want to go from:
class Classifier(object):
...
def classify(self, data):
# Do some approximate stuff with the data and other
# instance members.
to
class TruthComparer(object):
def compute_and_store_stats(self, data, accessory_data):
# Do the exact computation, compare to the approximation,
# and store it.
def get_comparison_stats(self):
# Return detailed and aggregate information about the
# differences between the truth and the approximation.
class Classifier(object):
...
def classify(self, data, truth_comparer=None):
# Do some approximate stuff with the data and other
# instance members.
# Optionally, do exact stuff with the data and other
# instance members, storing info about differences
# between the exact computation and the approximation
# in the truth_comparer
if truth_comparer is not None:
truth_comparer.compute_and_store_stats(data,
[self._index, self._model],
intermediate_approximation)
The reason I don't want to do those comparisons inline within the classify
method is that I don't think it fits the job of that method or object to do those comparisons.
So, what design pattern, if any, is this? Can you suggest an alternative?