I wonder whether this pattern that I have frequently used is common and has a name:
- an algorithm is a class
- its parameters are passed via the constructor of the class
- calling a parameter-less
runmethod triggers the computation - the result(s) are fetched by calling getter methods
An example (in Python for simplicity):
class MyAlgorithm:
def __init__(self, input, param1, param2):
self.param1 = param1
self.param2 = param2
self.input = input
def run(self):
...
return self
def getResultA(self):
...
def getResultB(self):
...
As a second question: What are the pros and cons of this pattern? Is there a good reason to have a separate run-method rather than having the constructor do the computation?
Aucun commentaire:
Enregistrer un commentaire