I have an algorithm that performs the same tasks on different datasets. Essentially the methods are the same but the parameters are different. I'm trying to create classes for this but since I'm not familiar with OOP design principles I'm a bit confused how to do this.
Since, the algorithm is the same I figured I can create a common Class from which classes related to the two different datasets inherit from. For example,
class MyAlgorithm():
def __init__(self, dataset):
self.dataset = dataset
def step1():
# do sth with dataset
def step2():
# do sth with result of step1()
class Dataset1Class(MyAlgorithm):
def __init__(self, dataset):
self.dateset = dateset
class Dataset2Class(MyAlgorithm):
def __init__(self, dataset):
self.dateset = dateset
I'm simplifying it here a bit and the datasource is actually a database but I think this may not be the best way to do it. So, I wonder how an experienced Pythonista would do it. Is there another better way to do this? This code is part of a larger codebase and will eventually be called from a Celery worker process along with the rest of the data pipeline.
Aucun commentaire:
Enregistrer un commentaire